Skip to content

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

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

Conversation

warslett
Copy link
Contributor

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

okay I found the test: RedisAdapterSentinelTest will update

@warslett
Copy link
Contributor Author

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 July 28, 2022 15:25
@nicolas-grekas
Copy link
Member

Good catch, thanks @warslett.

@nicolas-grekas nicolas-grekas merged commit 8341158 into symfony:5.4 Jul 28, 2022
This was referenced Jul 29, 2022
@warslett warslett deleted the 46998-cache-comp-redis-sentinel-multihost-fix branch August 1, 2022 08:10
nicolas-grekas added a commit that referenced this pull request Sep 20, 2023
…sts (digilist)

This PR was merged into the 6.4 branch.

Discussion
----------

[Messenger] Add support for multiple Redis Sentinel hosts

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

Similar to #47003 which added support for multiple Redis Sentinel hosts for the Cache component, this PR adds support for multiple Sentinel hosts for the Messenger component.

This PR is inspired by the implementation in the cache component and works very similar. A DSN could look like this: `redis:?host[localhost:26377]&host[localhost:26379]&sentinel_master=db`.

I changed the Sentinel host environment variable for the ingegration to an invalid host at. As a result I noticed that Relay also fails in such case and so I expanded my earlier changes from #51598 to also ignore unreachable hosts with the Relay extension.

Commits
-------

3380518 [Messenger] Add support for multiple Redis Sentinel hosts
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.

3 participants