Skip to content

Commit

Permalink
bug #33797 [Cache] Fixed Redis Sentinel usage when only one Sentinel …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Oct 2, 2019
2 parents 526fd9f + 13233fc commit 7020f26
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Expand Up @@ -271,7 +271,7 @@ public static function createConnection($dsn, array $options = [])
if (null !== $auth) {
$params['parameters']['password'] = $auth;
}
if (1 === \count($hosts) && !$params['redis_cluster']) {
if (1 === \count($hosts) && !($params['redis_cluster'] || $params['redis_sentinel'])) {
$hosts = $hosts[0];
} elseif (\in_array($params['failover'], ['slaves', 'distribute'], true) && !isset($params['replication'])) {
$params['replication'] = true;
Expand Down

0 comments on commit 7020f26

Please sign in to comment.