@@ -44,8 +44,8 @@ trait RedisTrait
44
44
'retry_interval ' => 0 ,
45
45
'tcp_keepalive ' => 0 ,
46
46
'lazy ' => null ,
47
- 'redis_cluster ' => false ,
48
- 'redis_sentinel ' => null ,
47
+ 'cluster ' => false ,
48
+ 'sentinel_master ' => null ,
49
49
'dbindex ' => 0 ,
50
50
'failover ' => 'none ' ,
51
51
'ssl ' => null , // see https://php.net/context.ssl
@@ -87,13 +87,13 @@ private function init(\Redis|Relay|\RedisArray|\RedisCluster|\Predis\ClientInter
87
87
*/
88
88
public static function createConnection (#[\SensitiveParameter] string $ dsn , array $ options = []): \Redis |\RedisArray |\RedisCluster |\Predis \ClientInterface |Relay
89
89
{
90
- if ( str_starts_with ( $ dsn , ' redis: ' ) ) {
91
- $ scheme = 'redis ' ;
92
- } elseif ( str_starts_with ($ dsn , 'rediss: ' )) {
93
- $ scheme = ' rediss ' ;
94
- } else {
95
- throw new InvalidArgumentException ('Invalid Redis DSN: it does not start with "redis[s]:". ' );
96
- }
90
+ $ scheme = match ( true ) {
91
+ str_starts_with ( $ dsn , ' redis: ' ) => 'redis: ' ,
92
+ str_starts_with ($ dsn , 'rediss: ' ) => ' rediss: ' ,
93
+ str_starts_with ( $ dsn , ' valkey: ' ) => ' valkey: ' ,
94
+ str_starts_with ( $ dsn , ' valkeys: ' ) => ' valkeys: ' ,
95
+ default => throw new InvalidArgumentException ('Invalid Redis DSN: it does not start with "redis[s]:" nor "valkey[s]:" . ' ),
96
+ };
97
97
98
98
if (!\extension_loaded ('redis ' ) && !class_exists (\Predis \Client::class)) {
99
99
throw new CacheException ('Cannot find the "redis" extension nor the "predis/predis" package. ' );
@@ -121,7 +121,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
121
121
122
122
$ query = $ hosts = [];
123
123
124
- $ tls = 'rediss ' === $ scheme ;
124
+ $ tls = 'rediss ' === $ scheme || ' valkeys ' === $ scheme ;
125
125
$ tcpScheme = $ tls ? 'tls ' : 'tcp ' ;
126
126
127
127
if (isset ($ params ['query ' ])) {
@@ -178,24 +178,24 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
178
178
throw new InvalidArgumentException ('Cannot use both "redis_sentinel" and "sentinel_master" at the same time. ' );
179
179
}
180
180
181
- $ params ['redis_sentinel ' ] ??= $ params ['sentinel_master ' ] ?? null ;
181
+ $ params ['sentinel_master ' ] ??= $ params ['redis_sentinel ' ] ?? null ;
182
182
183
- if (isset ($ params ['redis_sentinel ' ]) && !class_exists (\Predis \Client::class) && !class_exists (\RedisSentinel::class) && !class_exists (Sentinel::class)) {
183
+ if (isset ($ params ['sentinel_master ' ]) && !class_exists (\Predis \Client::class) && !class_exists (\RedisSentinel::class) && !class_exists (Sentinel::class)) {
184
184
throw new CacheException ('Redis Sentinel support requires one of: "predis/predis", "ext-redis >= 5.2", "ext-relay". ' );
185
185
}
186
186
187
187
if (isset ($ params ['lazy ' ])) {
188
188
$ params ['lazy ' ] = filter_var ($ params ['lazy ' ], \FILTER_VALIDATE_BOOLEAN );
189
189
}
190
- $ params ['redis_cluster ' ] = filter_var ($ params ['redis_cluster ' ], \FILTER_VALIDATE_BOOLEAN );
190
+ $ params ['cluster ' ] = filter_var ( $ params [ ' cluster ' ], \ FILTER_VALIDATE_BOOLEAN ) || filter_var ($ params ['redis_cluster ' ], \FILTER_VALIDATE_BOOLEAN );
191
191
192
- if ($ params ['redis_cluster ' ] && isset ($ params ['redis_sentinel ' ])) {
193
- throw new InvalidArgumentException ('Cannot use both "redis_cluster " and "redis_sentinel " at the same time. ' );
192
+ if ($ params ['cluster ' ] && isset ($ params ['sentinel_master ' ])) {
193
+ throw new InvalidArgumentException ('Cannot use both "cluster " and "sentinel " at the same time. ' );
194
194
}
195
195
196
196
$ class = $ params ['class ' ] ?? match (true ) {
197
- $ params ['redis_cluster ' ] => \extension_loaded ('redis ' ) ? \RedisCluster::class : \Predis \Client::class,
198
- isset ($ params ['redis_sentinel ' ]) => match (true ) {
197
+ $ params ['cluster ' ] => \extension_loaded ('redis ' ) ? \RedisCluster::class : \Predis \Client::class,
198
+ isset ($ params ['sentinel_master ' ]) => match (true ) {
199
199
\extension_loaded ('redis ' ) => \Redis::class,
200
200
\extension_loaded ('relay ' ) => Relay::class,
201
201
default => \Predis \Client::class,
@@ -206,7 +206,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
206
206
default => \Predis \Client::class,
207
207
};
208
208
209
- if (isset ($ params ['redis_sentinel ' ]) && !is_a ($ class , \Predis \Client::class, true ) && !class_exists (\RedisSentinel::class) && !class_exists (Sentinel::class)) {
209
+ if (isset ($ params ['sentinel_master ' ]) && !is_a ($ class , \Predis \Client::class, true ) && !class_exists (\RedisSentinel::class) && !class_exists (Sentinel::class)) {
210
210
throw new CacheException (\sprintf ('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and neither ext-redis >= 5.2 nor ext-relay have been found. ' , $ class ));
211
211
}
212
212
@@ -230,7 +230,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
230
230
$ host = 'tls:// ' .$ host ;
231
231
}
232
232
233
- if (!isset ($ params ['redis_sentinel ' ])) {
233
+ if (!isset ($ params ['sentinel_master ' ])) {
234
234
break ;
235
235
}
236
236
@@ -256,15 +256,15 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
256
256
$ sentinel = @new $ sentinelClass ($ host , $ port , $ params ['timeout ' ], (string ) $ params ['persistent_id ' ], $ params ['retry_interval ' ], $ params ['read_timeout ' ], ...$ extra );
257
257
}
258
258
259
- if ($ address = @$ sentinel ->getMasterAddrByName ($ params ['redis_sentinel ' ])) {
259
+ if ($ address = @$ sentinel ->getMasterAddrByName ($ params ['sentinel_master ' ])) {
260
260
[$ host , $ port ] = $ address ;
261
261
}
262
262
} catch (\RedisException |\Relay \Exception $ redisException ) {
263
263
}
264
264
} while (++$ hostIndex < \count ($ hosts ) && !$ address );
265
265
266
- if (isset ($ params ['redis_sentinel ' ]) && !$ address ) {
267
- throw new InvalidArgumentException (\sprintf ('Failed to retrieve master information from sentinel "%s". ' , $ params ['redis_sentinel ' ]), previous: $ redisException ?? null );
266
+ if (isset ($ params ['sentinel_master ' ]) && !$ address ) {
267
+ throw new InvalidArgumentException (\sprintf ('Failed to retrieve master information from sentinel "%s". ' , $ params ['sentinel_master ' ]), previous: $ redisException ?? null );
268
268
}
269
269
270
270
try {
@@ -379,11 +379,11 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
379
379
380
380
$ redis = $ params ['lazy ' ] ? RedisClusterProxy::createLazyProxy ($ initializer ) : $ initializer ();
381
381
} elseif (is_a ($ class , \Predis \ClientInterface::class, true )) {
382
- if ($ params ['redis_cluster ' ]) {
382
+ if ($ params ['cluster ' ]) {
383
383
$ params ['cluster ' ] = 'redis ' ;
384
- } elseif (isset ($ params ['redis_sentinel ' ])) {
384
+ } elseif (isset ($ params ['sentinel_master ' ])) {
385
385
$ params ['replication ' ] = 'sentinel ' ;
386
- $ params ['service ' ] = $ params ['redis_sentinel ' ];
386
+ $ params ['service ' ] = $ params ['sentinel_master ' ];
387
387
}
388
388
$ params += ['parameters ' => []];
389
389
$ params ['parameters ' ] += [
@@ -411,7 +411,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
411
411
}
412
412
}
413
413
414
- if (1 === \count ($ hosts ) && !($ params ['redis_cluster ' ] || $ params ['redis_sentinel ' ])) {
414
+ if (1 === \count ($ hosts ) && !($ params ['cluster ' ] || $ params ['sentinel_master ' ])) {
415
415
$ hosts = $ hosts [0 ];
416
416
} elseif (\in_array ($ params ['failover ' ], ['slaves ' , 'distribute ' ], true ) && !isset ($ params ['replication ' ])) {
417
417
$ params ['replication ' ] = true ;
@@ -420,7 +420,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
420
420
$ params ['exceptions ' ] = false ;
421
421
422
422
$ redis = new $ class ($ hosts , array_diff_key ($ params , self ::$ defaultConnectionOptions ));
423
- if (isset ($ params ['redis_sentinel ' ])) {
423
+ if (isset ($ params ['sentinel_master ' ])) {
424
424
$ redis ->getConnection ()->setSentinelTimeout ($ params ['timeout ' ]);
425
425
}
426
426
} elseif (class_exists ($ class , false )) {
0 commit comments