@@ -98,29 +98,34 @@ function __construct($search = null) { parent::__construct('user', $search); }
9898
9999 if (ENABLE_REDIS ) {
100100 $ redis = new Redis ();
101- $ redis ->connect (REDIS_HOST , REDIS_PORT );
102101
103- if (! empty ( REDIS_PASSWORD ))
104- $ redis ->auth ( REDIS_PASSWORD );
102+ try {
103+ $ redis ->connect ( REDIS_HOST , REDIS_PORT );
105104
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 );
110107
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 ' ) ;
115112
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 ' ];
117117
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 ' ) ) {
119124 $ redis ->flushDb ();
120125 redirect ('? ' );
121126 }
122127
123- if ( is_action ('redis_delete ' ) ) {
128+ if ( $ redis -> isConnected () && is_action ('redis_delete ' ) ) {
124129 $ list = redis_keys (get_selector ());
125130
126131 foreach ($ list as $ key => $ item )
@@ -817,7 +822,7 @@ function sort_list($list) {
817822 </div>
818823 <?php endif ; ?>
819824
820- <?php if (ENABLE_REDIS ): ?>
825+ <?php if (ENABLE_REDIS && $ redis -> isConnected () ): ?>
821826 <h2 id="redis">Redis</h2>
822827 <div>
823828 <h3>Memory <?= human_size (redis_mem ('used ' ) + redis_mem ('hash ' ))?> of <?= human_size (redis_mem ('total ' ))?> </h3>
0 commit comments