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
bug #47003 [Cache] Ensured that redis adapter can use multiple redis sentinel hosts (warslett)
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[Cache] Ensured that redis adapter can use multiple redis sentinel hosts
This PR ensures that RedisAdapter for Symfony Cache component works as expected when a redis_sentinel argument is provided with multiple redis sentinel hosts. Previously if using the redis php extension and multiple hosts were provided RedisTrait::createConnection would ignore the redis_sentinel parameter and instead return a RedisArray object which would not work because it would be an array of sentinel hosts rather than redis hosts.
This PR introduces the correct behaviour where by RedisTrait::createConnection will loop through each of the provided sentinel hosts trying each one to get the address of the mast redis instance. If none of the provided hosts can return the address of a master instance it will throw an exception.
I'm not too sure how to test this behaviour. There doesn't appear to be any tests for redis sentinel behaviour in place currently. I have tested manually both with a multi redis sentinel setup and with a single standard redis instance and the code now functions as expected in both scenarios.
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes/no
| New feature? | no - bugfix
| Deprecations? | no - behaviour as documented and as implemented in 4.4
| Tickets | [#46998](#46998)
| License | MIT
| Doc PR | none - bugfix
Commits
-------
39998d3 [Cache] Ensured that redis adapter can use multiple redis sentinel hosts
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
205
211
206
-
if (!$address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
207
-
thrownewInvalidArgumentException(sprintf('Failed to retrieve master information from master name "%s" and address "%s:%d".', $params['redis_sentinel'], $host, $port));
212
+
if ($address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
213
+
[$host, $port] = $address;
208
214
}
215
+
} while (++$hostIndex < \count($hosts) && !$address);
209
216
210
-
[$host, $port] = $address;
217
+
if (isset($params['redis_sentinel']) && !$address) {
218
+
thrownewInvalidArgumentException(sprintf('Failed to retrieve master information from sentinel "%s" and dsn "%s".', $params['redis_sentinel'], $dsn));
0 commit comments