Databases 6 min read

How Redis Sentinel Ensures Automatic Failover and High Availability

Redis Sentinel provides an automated high‑availability solution for Redis by monitoring master health, broadcasting SDOWN/ODOWN messages, electing a new master based on priority, offset and runid, and allowing clients to discover the current master via sentinel commands, all explained with configuration examples and diagrams.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How Redis Sentinel Ensures Automatic Failover and High Availability

How It Works?

Redis Sentinel monitors a master and its slaves. When a sentinel detects that the master is unresponsive, it broadcasts an SDOWN (subjectively down) message to other sentinels. Once a quorum of sentinels agrees, an ODOWN (objectively down) message is broadcast, triggering a transparent failover to a new master.

Example scenario: Redis A is the master, B and C are slaves, and three sentinels run on application servers. If A fails, a sentinel sends SDOWN, followed by ODOWN from the others. A new master (e.g., B) is elected, C replicates B, and clients reconnect to B. When A recovers, it becomes a slave of B.

Core Configuration Items

sentinel monitor myHAsetup 192.168.1.29 6379 2
ip port

specifies the master to monitor; the final 2 indicates the minimum number of sentinels that must agree the master is down; myHAsetup is the custom master group name. sentinel down-after-milliseconds myHAsetup 6001 Defines the time in milliseconds after which a master is considered down. sentinel failover-timeout myHAsetup 60000 Sets the timeout for a failover operation; if exceeded, another sentinel may attempt failover. sentinel parallel-syncs myHAsetup 1 Specifies how many slaves can be synchronized with the new master simultaneously during failover.

How Is a New Master Chosen?

Sentinel selects a new master using the following rules:

Prefer the instance with the lowest priority (default 100).

If priorities are equal, choose the slave with the larger replication offset.

If offsets are also equal, select the instance with the smaller runid (a random string generated at startup).

Which Sentinel Executes the Failover?

When multiple sentinels are present, they elect a leader using a Raft‑based consensus algorithm to perform the failover.

How Does Sentinel Discover Slaves and Other Sentinels?

Sentinel learns slave addresses by querying the master. It discovers other sentinels via a publish/subscribe channel __sentinel__:hello, where each sentinel broadcasts its presence every second and subscribes to the same channel.

How Do Clients Learn the New Master Address After Failover?

Clients can query a sentinel for the current master using the command:

redis-cli -p 26379 -h 192.168.1.29 sentinel get-master-addr-by-name myHAsetup

The response returns the master’s IP and port. Clients using a Redis library that supports sentinel will automatically obtain the updated master address.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringhigh availabilityredisConfigurationsentinel
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.