-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Symfony version(s) affected
6.4
Description
An exception is thrown when trying to connect the Redis Cache adapter to a Redis Cluster which has mandatory authentication enabled.
How to reproduce
RedisAdapter::createConnection("rediss://user:password@host:port", ['redis_cluster'=> true]);Expected result: working Redis connection
Actual result: Exception "Couldn't map cluster keyspace using any provided seed"
Possible Solution
The problem is in line 413 of /src/Symfony/Component/Cache/Traits/RedisTrait.php:
$redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], $params['persistent'], $params['auth'] ?? '', ...\defined('Redis::SCAN_PREFIX') ? [$params['ssl'] ?? null] : []);Parameter 6 of the constructor is supposed to contain the authentication parameters. These were extracted from the DSN earlier into the $auth variable and are not present anymore in the $hosts array. $params['auth'] also does not contain them. However there is a
Verified workaround:
Add the auth in the query parameters of the DSN:
RedisAdapter::createConnection("rediss://host:port?auth[0]=user&auth[1]=password", ['redis_cluster'=> true]);This places them in the $params['auth'] and it works.
Note that the auth parameters in DSN are undocumented.
Additional Context
Requirements:
ext_phpredisPHP extension- A Redis Cluster with mandatory authentication
Additional parameters for the environment in which this was observed, but which are probably irrelevant:
- PHP 8.3
- Symfony framework 6.4
- Docker container on Linux host