How does an application discover the current primary Redis instance when using Sentinel, especially after a failover has occurred?
Short answer
Rather than connecting directly to a specific server address, a Sentinel aware client library asks one of the Sentinel instances for the current address of the primary, and after a failover happens, subsequent queries to Sentinel automatically return the new primary's address…
Advertisement
AModel answer
Rather than connecting directly to a specific server address, a Sentinel aware client library asks one of the Sentinel instances for the current address of the primary, and after a failover happens, subsequent queries to Sentinel automatically return the new primary's address, letting the application always connect to the correct, currently active primary.
Example
-- Client asks Sentinel for the current primary address SENTINEL get-master-addr-by-name mymaster
Real-world example
An application configured with a Sentinel aware client library automatically reconnects to the newly promoted primary after a failover, since it always asks Sentinel for the current address rather than hardcoding a specific server.
Likely follow-ups
- What happens to an application's existing connections during the brief period while a failover is happening?
- Do all Redis client libraries support Sentinel awareness?
Related topics