@@ -96,11 +96,11 @@ public static function createConnection(string $dsn, array $options = [])
96
96
} elseif (str_starts_with ($ dsn , 'rediss: ' )) {
97
97
$ scheme = 'rediss ' ;
98
98
} 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]:". ' );
100
100
}
101
101
102
102
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. ' );
104
104
}
105
105
106
106
$ params = preg_replace_callback ('#^ ' .$ scheme .':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?# ' , function ($ m ) use (&$ auth ) {
@@ -116,7 +116,7 @@ public static function createConnection(string $dsn, array $options = [])
116
116
}, $ dsn );
117
117
118
118
if (false === $ params = parse_url ($ params )) {
119
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
119
+ throw new InvalidArgumentException ('Invalid Redis DSN. ' );
120
120
}
121
121
122
122
$ query = $ hosts = [];
@@ -129,7 +129,7 @@ public static function createConnection(string $dsn, array $options = [])
129
129
130
130
if (isset ($ query ['host ' ])) {
131
131
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. ' );
133
133
}
134
134
foreach ($ hosts as $ host => $ parameters ) {
135
135
if (\is_string ($ parameters )) {
@@ -153,7 +153,7 @@ public static function createConnection(string $dsn, array $options = [])
153
153
$ params ['dbindex ' ] = $ m [1 ] ?? '0 ' ;
154
154
$ params ['path ' ] = substr ($ params ['path ' ], 0 , -\strlen ($ m [0 ]));
155
155
} 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. ' );
157
157
}
158
158
}
159
159
@@ -165,13 +165,13 @@ public static function createConnection(string $dsn, array $options = [])
165
165
}
166
166
167
167
if (!$ hosts ) {
168
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
168
+ throw new InvalidArgumentException ('Invalid Redis DSN: missing host. ' );
169
169
}
170
170
171
171
$ params += $ query + $ options + self ::$ defaultConnectionOptions ;
172
172
173
173
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. ' );
175
175
}
176
176
177
177
if (isset ($ params ['lazy ' ])) {
@@ -180,7 +180,7 @@ public static function createConnection(string $dsn, array $options = [])
180
180
$ params ['redis_cluster ' ] = filter_var ($ params ['redis_cluster ' ], \FILTER_VALIDATE_BOOLEAN );
181
181
182
182
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. ' );
184
184
}
185
185
186
186
if (null === $ params ['class ' ] && \extension_loaded ('redis ' )) {
@@ -189,15 +189,15 @@ public static function createConnection(string $dsn, array $options = [])
189
189
$ class = $ params ['class ' ] ?? \Predis \Client::class;
190
190
191
191
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 ));
193
193
}
194
194
}
195
195
196
196
if (is_a ($ class , \Redis::class, true )) {
197
197
$ connect = $ params ['persistent ' ] || $ params ['persistent_id ' ] ? 'pconnect ' : 'connect ' ;
198
198
$ redis = new $ class ();
199
199
200
- $ initializer = static function ($ redis ) use ($ connect , $ params , $ dsn , $ auth , $ hosts , $ tls ) {
200
+ $ initializer = static function ($ redis ) use ($ connect , $ params , $ auth , $ hosts , $ tls ) {
201
201
$ hostIndex = 0 ;
202
202
do {
203
203
$ host = $ hosts [$ hostIndex ]['host ' ] ?? $ hosts [$ hostIndex ]['path ' ];
@@ -243,7 +243,7 @@ public static function createConnection(string $dsn, array $options = [])
243
243
} while (++$ hostIndex < \count ($ hosts ) && !$ address );
244
244
245
245
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 ' ]));
247
247
}
248
248
249
249
try {
@@ -262,22 +262,22 @@ public static function createConnection(string $dsn, array $options = [])
262
262
restore_error_handler ();
263
263
}
264
264
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 .'. ' );
267
267
}
268
268
269
269
if ((null !== $ auth && !$ redis ->auth ($ auth ))
270
270
|| ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
271
271
) {
272
272
$ 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 .'. ' );
274
274
}
275
275
276
276
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
277
277
$ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
278
278
}
279
279
} catch (\RedisException $ e ) {
280
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
280
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
281
281
}
282
282
283
283
return true ;
@@ -302,14 +302,14 @@ public static function createConnection(string $dsn, array $options = [])
302
302
try {
303
303
$ redis = new $ class ($ hosts , $ params );
304
304
} catch (\RedisClusterException $ e ) {
305
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
305
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
306
306
}
307
307
308
308
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
309
309
$ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
310
310
}
311
311
} elseif (is_a ($ class , \RedisCluster::class, true )) {
312
- $ initializer = static function () use ($ class , $ params , $ dsn , $ hosts ) {
312
+ $ initializer = static function () use ($ class , $ params , $ hosts ) {
313
313
foreach ($ hosts as $ i => $ host ) {
314
314
switch ($ host ['scheme ' ]) {
315
315
case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ]; break ;
@@ -321,7 +321,7 @@ public static function createConnection(string $dsn, array $options = [])
321
321
try {
322
322
$ redis = new $ class (null , $ hosts , $ params ['timeout ' ], $ params ['read_timeout ' ], (bool ) $ params ['persistent ' ], $ params ['auth ' ] ?? '' , ...\defined ('Redis::SCAN_PREFIX ' ) ? [$ params ['ssl ' ] ?? null ] : []);
323
323
} catch (\RedisClusterException $ e ) {
324
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
324
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
325
325
}
326
326
327
327
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
0 commit comments