@@ -119,26 +119,26 @@ public static function createConnection($dsn, array $options = [])
119
119
$ initializer = function ($ redis ) use ($ connect , $ params , $ dsn , $ auth ) {
120
120
try {
121
121
@$ redis ->{$ connect }($ params ['host ' ], $ params ['port ' ], $ params ['timeout ' ], $ params ['persistent_id ' ], $ params ['retry_interval ' ]);
122
+
123
+ set_error_handler (function ($ type , $ msg ) use (&$ error ) { $ error = $ msg ; });
124
+ $ isConnected = $ redis ->isConnected ();
125
+ restore_error_handler ();
126
+ if (!$ isConnected ) {
127
+ $ error = preg_match ('/^Redis::p?connect\(\): (.*)/ ' , $ error , $ error ) ? sprintf (' (%s) ' , $ error [1 ]) : '' ;
128
+ throw new InvalidArgumentException (sprintf ('Redis connection "%s" failed: ' , $ dsn ).$ error .'. ' );
129
+ }
130
+
131
+ if ((null !== $ auth && !$ redis ->auth ($ auth ))
132
+ || ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
133
+ || ($ params ['read_timeout ' ] && !$ redis ->setOption (\Redis::OPT_READ_TIMEOUT , $ params ['read_timeout ' ]))
134
+ ) {
135
+ $ e = preg_replace ('/^ERR / ' , '' , $ redis ->getLastError ());
136
+ throw new InvalidArgumentException (sprintf ('Redis connection "%s" failed: ' , $ dsn ).$ e .'. ' );
137
+ }
122
138
} catch (\RedisException $ e ) {
123
139
throw new InvalidArgumentException (sprintf ('Redis connection "%s" failed: ' , $ dsn ).$ e ->getMessage ());
124
140
}
125
141
126
- set_error_handler (function ($ type , $ msg ) use (&$ error ) { $ error = $ msg ; });
127
- $ isConnected = $ redis ->isConnected ();
128
- restore_error_handler ();
129
- if (!$ isConnected ) {
130
- $ error = preg_match ('/^Redis::p?connect\(\): (.*)/ ' , $ error , $ error ) ? sprintf (' (%s) ' , $ error [1 ]) : '' ;
131
- throw new InvalidArgumentException (sprintf ('Redis connection "%s" failed: ' , $ dsn ).$ error .'. ' );
132
- }
133
-
134
- if ((null !== $ auth && !$ redis ->auth ($ auth ))
135
- || ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
136
- || ($ params ['read_timeout ' ] && !$ redis ->setOption (\Redis::OPT_READ_TIMEOUT , $ params ['read_timeout ' ]))
137
- ) {
138
- $ e = preg_replace ('/^ERR / ' , '' , $ redis ->getLastError ());
139
- throw new InvalidArgumentException (sprintf ('Redis connection "%s" failed: ' , $ dsn ).$ e .'. ' );
140
- }
141
-
142
142
return true ;
143
143
};
144
144
0 commit comments