You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
In a Redis Sentinel setup, if only a single Redis Sentinel is specified (as we're currently doing in a test environment), then the call to setSentinelTimeout in RedisTrait.php throws the exception:
Call to undefined method Predis\Connection\StreamConnection::setSentinelTimeout()
Looking briefly through the code, it appears that if only a single host has been specified, it never initialises properly as a SentinelReplication interface, instead defaulting as a StreamConnection. The setSentinelTimeout method isn't present, and so it throws an exception trying to call it.
How to reproduce
// WORKING: Two different hosts$redisSentinels = ['192.168.0.1:26379', '192.168.0.2:26379'];
// NOT WORKING: Single host, or the same host multiple times. i.e. You can't "trick" it.$redisSentinels = ['192.168.0.1:26379'];
$redisSentinels = ['192.168.0.1:26379', '192.168.0.1:26379'];
$redisAuthPassword = 'mypass';
$dsnHostsString = sprintf('?host[%s]', implode(']&host[', $redisSentinels));
$redisDsnString = sprintf('redis:%s@%s', $redisAuthPassword, $dsnHostsString);
$redisOptions = array(
'compression' => true,
'redis_sentinel' => 'name-of-redis-service'
);
$redisClient = RedisAdapter::createConnection($redisDsnString, $redisOptions);
if (1 === \count($hosts) && !$params['redis_cluster']) {
to
if (1 === \count($hosts) && !($params['redis_cluster'] || $params['redis_sentinel'])) {
This will prevent the line below from turning the list of host configs into a single host config when the 'redis_sentinel' parameter is present, and sets up the Connection class properly, preventing the error.
Additional context
Again, this is an unusual bug, in that when using Redis Sentinel you should generally have more than one Sentinel available, but it does cause issues in test platform infrastructure where this may not be the case.
The text was updated successfully, but these errors were encountered:
…specified (Rohaq)
This PR was merged into the 4.4 branch.
Discussion
----------
[Cache] Fixed Redis Sentinel usage when only one Sentinel specified
Added check for $params['redis_sentinel'] to line 274, as by converting the array of hosts to a single host configuration (as you might in a test environment), this causes the class to initialise incorrectly.
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#33796
| License | MIT
| Doc PR |
As from Issue #33796
In a Redis Sentinel setup, if only a single Redis Sentinel, or multiple Sentinels with the same host/port are specified (as we're currently doing in a test environment), then the call to `setSentinelTimeout` in `RedisTrait.php` throws an exception, as the wrong interface appears to be initialised as a result.
Adding a check for the `redis_sentinel` parameter, as was done with a check for the `redis_cluster` parameter, avoids this, and the Redis Client is initialised correctly.
Commits
-------
13233fc Fixed Redis Sentinel usage when only one Sentinel specified
Symfony version(s) affected: 4.4.x-dev [660b7b4bb4ae391ef2c61d73d258c8ef3c563b66]
Description
In a Redis Sentinel setup, if only a single Redis Sentinel is specified (as we're currently doing in a test environment), then the call to
setSentinelTimeout
inRedisTrait.php
throws the exception:Looking briefly through the code, it appears that if only a single host has been specified, it never initialises properly as a
SentinelReplication
interface, instead defaulting as aStreamConnection
. ThesetSentinelTimeout
method isn't present, and so it throws an exception trying to call it.How to reproduce
Possible Solution
In RedisTrait.php, line 274, change:
to
This will prevent the line below from turning the list of host configs into a single host config when the 'redis_sentinel' parameter is present, and sets up the Connection class properly, preventing the error.
Additional context
Again, this is an unusual bug, in that when using Redis Sentinel you should generally have more than one Sentinel available, but it does cause issues in test platform infrastructure where this may not be the case.
The text was updated successfully, but these errors were encountered: