Closed
Description
Symfony version(s) affected
6.3.0
Description
When trying to initialize a redis cluster connection through symfony/cache RedisAdapter::createConnection, the method returns a RedisArray instead of a RedisCluster
With this issue, i have to manually set the class in the DSN to \RedisCluster in order for it to work.
How to reproduce
Simply pass one of the following strings as DSN to the method :
RedisAdapter::createConnection('redis:?host[redis_cluster:7000]&host[redis_cluster:7001]&redis_cluster=1&timeout=1&read_timeout=2&persistent=1')
RedisAdapter::createConnection('redis:?host[redis_cluster:7000]&host[redis_cluster:7001]&redis_cluster=true&timeout=1&read_timeout=2&persistent=1')
You will get a RedisArray class.
Possible Solution
In the RedisTrait class, starting from line 180 :
$class = $params['class'] ?? match (true) {
(bool) $params['redis_cluster'] => \extension_loaded('redis') ? \RedisCluster::class : \Predis\Client::class,
isset($params['redis_sentinel']) => match (true) {
\extension_loaded('redis') => \Redis::class,
\extension_loaded('relay') => Relay::class,
default => \Predis\Client::class,
},
1 < \count($hosts) && \extension_loaded('redis') => 1 < \count($hosts) ? \RedisArray::class : \Redis::class,
\extension_loaded('redis') => \Redis::class,
\extension_loaded('relay') => Relay::class,
default => \Predis\Client::class,
};
Additional Context
No response