Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cache] Ensured that redis adapter can use multiple redis sentinel hosts #47003

Conversation

warslett
Copy link
Contributor

@warslett warslett commented Jul 21, 2022

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
License MIT
Doc PR none - bugfix

@warslett
Copy link
Contributor Author

@warslett warslett commented Jul 21, 2022

okay I found the test: RedisAdapterSentinelTest will update

@warslett
Copy link
Contributor Author

@warslett warslett commented Jul 22, 2022

I've added multiple sentinel hosts to integration-tests.yml which makes it configure more like a real sentinel setup and I believe would have caught this bug (even though each provided host is actually the same address). I've also fixed the failing test due to the change in exception message.

@nicolas-grekas nicolas-grekas changed the title [Cache] Ensured that symfony cache component redis adapter can use multiple redis sentinel hosts [Cache] Ensured that redis adapter can use multiple redis sentinel hosts Jul 28, 2022
@nicolas-grekas nicolas-grekas force-pushed the 46998-cache-comp-redis-sentinel-multihost-fix branch from 7236258 to 39998d3 Compare Jul 28, 2022
@nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jul 28, 2022

Good catch, thanks @warslett.

@nicolas-grekas nicolas-grekas merged commit 8341158 into symfony:5.4 Jul 28, 2022
9 of 11 checks passed
This was referenced Jul 29, 2022
@warslett warslett deleted the 46998-cache-comp-redis-sentinel-multihost-fix branch Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants