@@ -98,29 +98,34 @@ function __construct($search = null) { parent::__construct('user', $search); }
98
98
99
99
if (ENABLE_REDIS ) {
100
100
$ redis = new Redis ();
101
- $ redis ->connect (REDIS_HOST , REDIS_PORT );
102
101
103
- if (! empty ( REDIS_PASSWORD ))
104
- $ redis ->auth ( REDIS_PASSWORD );
102
+ try {
103
+ $ redis ->connect ( REDIS_HOST , REDIS_PORT );
105
104
106
- $ redis_db = 0 ;
107
- $ redis_dbs = $ redis ->config ('GET ' , 'databases ' );
108
- $ redis_db_select = !is_numeric (REDIS_DATABASE ) && !empty ($ redis_dbs );
109
- $ redis_memory = $ redis ->info ('memory ' );
105
+ if (!empty (REDIS_PASSWORD ))
106
+ $ redis ->auth (REDIS_PASSWORD );
110
107
111
- if (! $ redis_db_select )
112
- $ redis_db = REDIS_DATABASE ;
113
- else if ( !empty ($ _COOKIE [ ' redis_db ' ]))
114
- $ redis_db = ( int ) $ _COOKIE [ ' redis_db ' ] ;
108
+ $ redis_db = 0 ;
109
+ $ redis_dbs = $ redis -> config ( ' GET ' , ' databases ' ) ;
110
+ $ redis_db_select = ! is_numeric ( REDIS_DATABASE ) && !empty ($ redis_dbs );
111
+ $ redis_memory = $ redis -> info ( ' memory ' ) ;
115
112
116
- $ redis ->select ($ redis_db );
113
+ if (!$ redis_db_select )
114
+ $ redis_db = REDIS_DATABASE ;
115
+ else if (!empty ($ _COOKIE ['redis_db ' ]))
116
+ $ redis_db = (int )$ _COOKIE ['redis_db ' ];
117
117
118
- if ( is_action ('redis_clear ' ) ) {
118
+ $ redis ->select ($ redis_db );
119
+ } catch (RedisException $ ex ) {
120
+ // Failed to connect
121
+ }
122
+
123
+ if ( $ redis ->isConnected () && is_action ('redis_clear ' ) ) {
119
124
$ redis ->flushDb ();
120
125
redirect ('? ' );
121
126
}
122
127
123
- if ( is_action ('redis_delete ' ) ) {
128
+ if ( $ redis -> isConnected () && is_action ('redis_delete ' ) ) {
124
129
$ list = redis_keys (get_selector ());
125
130
126
131
foreach ($ list as $ key => $ item )
@@ -817,7 +822,7 @@ function sort_list($list) {
817
822
</div>
818
823
<?php endif ; ?>
819
824
820
- <?php if (ENABLE_REDIS ): ?>
825
+ <?php if (ENABLE_REDIS && $ redis -> isConnected () ): ?>
821
826
<h2 id="redis">Redis</h2>
822
827
<div>
823
828
<h3>Memory <?= human_size (redis_mem ('used ' ) + redis_mem ('hash ' ))?> of <?= human_size (redis_mem ('total ' ))?> </h3>
0 commit comments