@@ -96,11 +96,11 @@ public static function createConnection(string $dsn, array $options = [])
9696 } elseif (str_starts_with ($ dsn , 'rediss: ' )) {
9797 $ scheme = 'rediss ' ;
9898 } else {
99- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s" does not start with "redis:" or "rediss". ' , $ dsn ) );
99+ throw new InvalidArgumentException ('Invalid Redis DSN: it does not start with "redis[s]:". ' );
100100 }
101101
102102 if (!\extension_loaded ('redis ' ) && !class_exists (\Predis \Client::class)) {
103- throw new CacheException (sprintf ( 'Cannot find the "redis" extension nor the "predis/predis" package: "%s". ' , $ dsn ) );
103+ throw new CacheException ('Cannot find the "redis" extension nor the "predis/predis" package. ' );
104104 }
105105
106106 $ params = preg_replace_callback ('#^ ' .$ scheme .':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?# ' , function ($ m ) use (&$ auth ) {
@@ -116,7 +116,7 @@ public static function createConnection(string $dsn, array $options = [])
116116 }, $ dsn );
117117
118118 if (false === $ params = parse_url ($ params )) {
119- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
119+ throw new InvalidArgumentException ('Invalid Redis DSN. ' );
120120 }
121121
122122 $ query = $ hosts = [];
@@ -129,7 +129,7 @@ public static function createConnection(string $dsn, array $options = [])
129129
130130 if (isset ($ query ['host ' ])) {
131131 if (!\is_array ($ hosts = $ query ['host ' ])) {
132- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
132+ throw new InvalidArgumentException ('Invalid Redis DSN: query parameter "host" must be an array. ' );
133133 }
134134 foreach ($ hosts as $ host => $ parameters ) {
135135 if (\is_string ($ parameters )) {
@@ -153,7 +153,7 @@ public static function createConnection(string $dsn, array $options = [])
153153 $ params ['dbindex ' ] = $ m [1 ] ?? '0 ' ;
154154 $ params ['path ' ] = substr ($ params ['path ' ], 0 , -\strlen ($ m [0 ]));
155155 } elseif (isset ($ params ['host ' ])) {
156- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s", the "dbindex" parameter must be a number. ' , $ dsn ) );
156+ throw new InvalidArgumentException ('Invalid Redis DSN: query parameter "dbindex" must be a number. ' );
157157 }
158158 }
159159
@@ -165,13 +165,13 @@ public static function createConnection(string $dsn, array $options = [])
165165 }
166166
167167 if (!$ hosts ) {
168- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
168+ throw new InvalidArgumentException ('Invalid Redis DSN: missing host. ' );
169169 }
170170
171171 $ params += $ query + $ options + self ::$ defaultConnectionOptions ;
172172
173173 if (isset ($ params ['redis_sentinel ' ]) && !class_exists (\Predis \Client::class) && !class_exists (\RedisSentinel::class)) {
174- throw new CacheException (sprintf ( 'Redis Sentinel support requires the "predis/predis" package or the "redis" extension v5.2 or higher: "%s". ' , $ dsn ) );
174+ throw new CacheException ('Redis Sentinel support requires the "predis/predis" package or the "redis" extension v5.2 or higher. ' );
175175 }
176176
177177 if (isset ($ params ['lazy ' ])) {
@@ -180,7 +180,7 @@ public static function createConnection(string $dsn, array $options = [])
180180 $ params ['redis_cluster ' ] = filter_var ($ params ['redis_cluster ' ], \FILTER_VALIDATE_BOOLEAN );
181181
182182 if ($ params ['redis_cluster ' ] && isset ($ params ['redis_sentinel ' ])) {
183- throw new InvalidArgumentException (sprintf ( 'Cannot use both "redis_cluster" and "redis_sentinel" at the same time: "%s". ' , $ dsn ) );
183+ throw new InvalidArgumentException ('Cannot use both "redis_cluster" and "redis_sentinel" at the same time. ' );
184184 }
185185
186186 if (null === $ params ['class ' ] && \extension_loaded ('redis ' )) {
@@ -189,15 +189,15 @@ public static function createConnection(string $dsn, array $options = [])
189189 $ class = $ params ['class ' ] ?? \Predis \Client::class;
190190
191191 if (isset ($ params ['redis_sentinel ' ]) && !is_a ($ class , \Predis \Client::class, true ) && !class_exists (\RedisSentinel::class)) {
192- throw new CacheException (sprintf ('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and ext-redis >= 5.2 not found: "%s" . ' , $ class, $ dsn ));
192+ throw new CacheException (sprintf ('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and ext-redis >= 5.2 not found. ' , $ class ));
193193 }
194194 }
195195
196196 if (is_a ($ class , \Redis::class, true )) {
197197 $ connect = $ params ['persistent ' ] || $ params ['persistent_id ' ] ? 'pconnect ' : 'connect ' ;
198198 $ redis = new $ class ();
199199
200- $ initializer = static function ($ redis ) use ($ connect , $ params , $ dsn , $ auth , $ hosts , $ tls ) {
200+ $ initializer = static function ($ redis ) use ($ connect , $ params , $ auth , $ hosts , $ tls ) {
201201 $ hostIndex = 0 ;
202202 do {
203203 $ host = $ hosts [$ hostIndex ]['host ' ] ?? $ hosts [$ hostIndex ]['path ' ];
@@ -243,7 +243,7 @@ public static function createConnection(string $dsn, array $options = [])
243243 } while (++$ hostIndex < \count ($ hosts ) && !$ address );
244244
245245 if (isset ($ params ['redis_sentinel ' ]) && !$ address ) {
246- throw new InvalidArgumentException (sprintf ('Failed to retrieve master information from sentinel "%s" and dsn "%s" . ' , $ params ['redis_sentinel ' ], $ dsn ));
246+ throw new InvalidArgumentException (sprintf ('Failed to retrieve master information from sentinel "%s". ' , $ params ['redis_sentinel ' ]));
247247 }
248248
249249 try {
@@ -262,22 +262,22 @@ public static function createConnection(string $dsn, array $options = [])
262262 restore_error_handler ();
263263 }
264264 if (!$ isConnected ) {
265- $ error = preg_match ('/^Redis::p?connect\(\): (.*)/ ' , $ error ?? '' , $ error ) ? sprintf (' (%s) ' , $ error [1 ]) : '' ;
266- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ error .'. ' );
265+ $ error = preg_match ('/^Redis::p?connect\(\): (.*)/ ' , $ error ?? $ redis -> getLastError () ?? '' , $ error ) ? sprintf (' (%s) ' , $ error [1 ]) : '' ;
266+ throw new InvalidArgumentException ('Redis connection failed: ' .$ error .'. ' );
267267 }
268268
269269 if ((null !== $ auth && !$ redis ->auth ($ auth ))
270270 || ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
271271 ) {
272272 $ e = preg_replace ('/^ERR / ' , '' , $ redis ->getLastError ());
273- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e .'. ' );
273+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e .'. ' );
274274 }
275275
276276 if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
277277 $ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
278278 }
279279 } catch (\RedisException $ e ) {
280- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
280+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
281281 }
282282
283283 return true ;
@@ -302,14 +302,14 @@ public static function createConnection(string $dsn, array $options = [])
302302 try {
303303 $ redis = new $ class ($ hosts , $ params );
304304 } catch (\RedisClusterException $ e ) {
305- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
305+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
306306 }
307307
308308 if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
309309 $ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
310310 }
311311 } elseif (is_a ($ class , \RedisCluster::class, true )) {
312- $ initializer = static function () use ($ class , $ params , $ dsn , $ hosts ) {
312+ $ initializer = static function () use ($ class , $ params , $ hosts ) {
313313 foreach ($ hosts as $ i => $ host ) {
314314 switch ($ host ['scheme ' ]) {
315315 case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ]; break ;
@@ -321,7 +321,7 @@ public static function createConnection(string $dsn, array $options = [])
321321 try {
322322 $ redis = new $ class (null , $ hosts , $ params ['timeout ' ], $ params ['read_timeout ' ], (bool ) $ params ['persistent ' ], $ params ['auth ' ] ?? '' , ...\defined ('Redis::SCAN_PREFIX ' ) ? [$ params ['ssl ' ] ?? null ] : []);
323323 } catch (\RedisClusterException $ e ) {
324- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
324+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
325325 }
326326
327327 if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
0 commit comments