@@ -87,11 +87,11 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
87
87
} elseif (str_starts_with ($ dsn , 'rediss: ' )) {
88
88
$ scheme = 'rediss ' ;
89
89
} else {
90
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s" does not start with "redis:" or "rediss". ' , $ dsn ) );
90
+ throw new InvalidArgumentException ('Invalid Redis DSN: it does not start with "redis[s]:". ' );
91
91
}
92
92
93
93
if (!\extension_loaded ('redis ' ) && !class_exists (\Predis \Client::class)) {
94
- throw new CacheException (sprintf ( 'Cannot find the "redis" extension nor the "predis/predis" package: "%s". ' , $ dsn ) );
94
+ throw new CacheException ('Cannot find the "redis" extension nor the "predis/predis" package. ' );
95
95
}
96
96
97
97
$ params = preg_replace_callback ('#^ ' .$ scheme .':(//)?(?:(?:(?<user>[^:@]*+):)?(?<password>[^@]*+)@)?# ' , function ($ m ) use (&$ auth ) {
@@ -111,7 +111,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
111
111
}, $ dsn );
112
112
113
113
if (false === $ params = parse_url ($ params )) {
114
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
114
+ throw new InvalidArgumentException ('Invalid Redis DSN. ' );
115
115
}
116
116
117
117
$ query = $ hosts = [];
@@ -124,7 +124,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
124
124
125
125
if (isset ($ query ['host ' ])) {
126
126
if (!\is_array ($ hosts = $ query ['host ' ])) {
127
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
127
+ throw new InvalidArgumentException ('Invalid Redis DSN: query parameter "host" must be an array. ' );
128
128
}
129
129
foreach ($ hosts as $ host => $ parameters ) {
130
130
if (\is_string ($ parameters )) {
@@ -148,7 +148,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
148
148
$ params ['dbindex ' ] = $ m [1 ];
149
149
$ params ['path ' ] = substr ($ params ['path ' ], 0 , -\strlen ($ m [0 ]));
150
150
} elseif (isset ($ params ['host ' ])) {
151
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s", the "dbindex" parameter must be a number. ' , $ dsn ) );
151
+ throw new InvalidArgumentException ('Invalid Redis DSN: query parameter "dbindex" must be a number. ' );
152
152
}
153
153
}
154
154
@@ -160,17 +160,17 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
160
160
}
161
161
162
162
if (!$ hosts ) {
163
- throw new InvalidArgumentException (sprintf ( 'Invalid Redis DSN: "%s". ' , $ dsn ) );
163
+ throw new InvalidArgumentException ('Invalid Redis DSN: missing host. ' );
164
164
}
165
165
166
166
$ params += $ query + $ options + self ::$ defaultConnectionOptions ;
167
167
168
168
if (isset ($ params ['redis_sentinel ' ]) && !class_exists (\Predis \Client::class) && !class_exists (\RedisSentinel::class)) {
169
- throw new CacheException (sprintf ( 'Redis Sentinel support requires the "predis/predis" package or the "redis" extension v5.2 or higher: "%s". ' , $ dsn ) );
169
+ throw new CacheException ('Redis Sentinel support requires the "predis/predis" package or the "redis" extension v5.2 or higher. ' );
170
170
}
171
171
172
172
if ($ params ['redis_cluster ' ] && isset ($ params ['redis_sentinel ' ])) {
173
- throw new InvalidArgumentException (sprintf ( 'Cannot use both "redis_cluster" and "redis_sentinel" at the same time: "%s". ' , $ dsn ) );
173
+ throw new InvalidArgumentException ('Cannot use both "redis_cluster" and "redis_sentinel" at the same time. ' );
174
174
}
175
175
176
176
if (null === $ params ['class ' ] && \extension_loaded ('redis ' )) {
@@ -179,14 +179,14 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
179
179
$ class = $ params ['class ' ] ?? \Predis \Client::class;
180
180
181
181
if (isset ($ params ['redis_sentinel ' ]) && !is_a ($ class , \Predis \Client::class, true ) && !class_exists (\RedisSentinel::class)) {
182
- 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 ));
182
+ throw new CacheException (sprintf ('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and ext-redis >= 5.2 not found. ' , $ class ));
183
183
}
184
184
}
185
185
186
186
if (is_a ($ class , \Redis::class, true )) {
187
187
$ connect = $ params ['persistent ' ] || $ params ['persistent_id ' ] ? 'pconnect ' : 'connect ' ;
188
188
189
- $ initializer = static function () use ($ class , $ connect , $ params , $ dsn , $ auth , $ hosts , $ tls ) {
189
+ $ initializer = static function () use ($ class , $ connect , $ params , $ auth , $ hosts , $ tls ) {
190
190
$ redis = new $ class ();
191
191
$ hostIndex = 0 ;
192
192
do {
@@ -213,7 +213,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
213
213
} while (++$ hostIndex < \count ($ hosts ) && !$ address );
214
214
215
215
if (isset ($ params ['redis_sentinel ' ]) && !$ address ) {
216
- throw new InvalidArgumentException (sprintf ('Failed to retrieve master information from sentinel "%s" and dsn "%s" . ' , $ params ['redis_sentinel ' ], $ dsn ));
216
+ throw new InvalidArgumentException (sprintf ('Failed to retrieve master information from sentinel "%s". ' , $ params ['redis_sentinel ' ]));
217
217
}
218
218
219
219
try {
@@ -233,21 +233,21 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
233
233
}
234
234
if (!$ isConnected ) {
235
235
$ error = preg_match ('/^Redis::p?connect\(\): (.*)/ ' , $ error ?? $ redis ->getLastError () ?? '' , $ error ) ? sprintf (' (%s) ' , $ error [1 ]) : '' ;
236
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ error .'. ' );
236
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ error .'. ' );
237
237
}
238
238
239
239
if ((null !== $ auth && !$ redis ->auth ($ auth ))
240
240
|| ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
241
241
) {
242
242
$ e = preg_replace ('/^ERR / ' , '' , $ redis ->getLastError ());
243
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e .'. ' );
243
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e .'. ' );
244
244
}
245
245
246
246
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
247
247
$ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
248
248
}
249
249
} catch (\RedisException $ e ) {
250
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
250
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
251
251
}
252
252
253
253
return $ redis ;
@@ -268,14 +268,14 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
268
268
try {
269
269
$ redis = new $ class ($ hosts , $ params );
270
270
} catch (\RedisClusterException $ e ) {
271
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
271
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
272
272
}
273
273
274
274
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
275
275
$ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
276
276
}
277
277
} elseif (is_a ($ class , \RedisCluster::class, true )) {
278
- $ initializer = static function () use ($ class , $ params , $ dsn , $ hosts ) {
278
+ $ initializer = static function () use ($ class , $ params , $ hosts ) {
279
279
foreach ($ hosts as $ i => $ host ) {
280
280
$ hosts [$ i ] = match ($ host ['scheme ' ]) {
281
281
'tcp ' => $ host ['host ' ].': ' .$ host ['port ' ],
@@ -287,7 +287,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
287
287
try {
288
288
$ redis = new $ class (null , $ hosts , $ params ['timeout ' ], $ params ['read_timeout ' ], (bool ) $ params ['persistent ' ], $ params ['auth ' ] ?? '' , ...\defined ('Redis::SCAN_PREFIX ' ) ? [$ params ['ssl ' ] ?? null ] : []);
289
289
} catch (\RedisClusterException $ e ) {
290
- throw new InvalidArgumentException (sprintf ( 'Redis connection "%s" failed: ' , $ dsn ) .$ e ->getMessage ());
290
+ throw new InvalidArgumentException ('Redis connection failed: ' .$ e ->getMessage ());
291
291
}
292
292
293
293
if (0 < $ params ['tcp_keepalive ' ] && \defined ('Redis::OPT_TCP_KEEPALIVE ' )) {
0 commit comments