What is Redis Sentinel?
Redis Sentinel is a high-availability solution that monitors a Redis master-replica topology and automatically promotes a replica (failover) when the master fails. It runs as a separate process and performs the following roles:
- Monitoring: Continuously checks that the master and replicas are alive
- Notification: Emits events when a failure occurs
- Automatic failover: Promotes a replica when the master goes down
- Service discovery: Provides clients with the current master address
Sentinel is not data sharding. If your goal is distributing data, use Redis Cluster. Sentinel is responsible for the availability of a single master.
Recommended Topology
The most common setup is 1 master + 2 replicas + 3 Sentinels.
| Node | IP | Role |
|---|---|---|
| node1 | 192.168.1.21 | Redis Master + Sentinel |
| node2 | 192.168.1.22 | Redis Replica + Sentinel |
| node3 | 192.168.1.23 | Redis Replica + Sentinel |
You must run an odd number of Sentinels (3 or more). That way, if the network partitions, majority (quorum) voting ensures only one side proceeds with failover.
1. Redis Replication Setup
First, create a standard master-replica topology.
Master (node1) redis.conf:
bind 0.0.0.0 -::1
port 6379
requirepass MasterAuth!2026
masterauth MasterAuth!2026
appendonly yesReplica (node2, node3) redis.conf:
bind 0.0.0.0 -::1
port 6379
requirepass MasterAuth!2026
masterauth MasterAuth!2026
replicaof 192.168.1.21 6379
appendonly yesSet masterauth and requirepass to the same values on every node so that after failover, connections to the new master still work. Check replication status with:
redis-cli -a MasterAuth!2026 info replication# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.22,port=6379,state=online,offset=...2. Sentinel Configuration
sentinel.conf on each node:
port 26379
bind 0.0.0.0
# when : <> <ip> <port> <quorum>
# quorum 2 = 2 Sentinel when
sentinel monitor mymaster 192.168.1.21 6379 2
# (requirepass when using required)
sentinel auth-pass mymaster MasterAuth!2026
# reply (SDOWN) when(ms)
sentinel down-after-milliseconds mymaster 5000
# when
sentinel parallel-syncs mymaster 1
# (ms)
sentinel failover-timeout mymaster 60000quorum is the number of Sentinels that must agree to start a failover. Actually executing the failover additionally requires a majority vote of all Sentinels. With 3 Sentinels, quorum 2 is the standard.
Run:
redis-sentinel /etc/redis/sentinel.conf
# or systemd
sudo systemctl enable --now redis-sentinel3. Verify Operation
redis-cli -p 26379 sentinel master mymaster
redis-cli -p 26379 sentinel replicas mymaster
redis-cli -p 26379 sentinel sentinels mymasterTo quickly query only the current master address:
redis-cli -p 26379 sentinel get-master-addr-by-name mymaster
# 1) "192.168.1.21"
# 2) "6379"4. SDOWN and ODOWN — Failover Decision Flow
| Stage | Abbreviation | Meaning |
|---|---|---|
| Subjective down | SDOWN | One Sentinel judges the master unresponsive |
| Objective down | ODOWN | A quorum of Sentinels agree on SDOWN |
| Leader election | — | Sentinels vote to elect a failover leader |
| Promotion | — | The leader promotes a suitable replica to new master |
Replica promotion priority is determined by replica-priority (lower is preferred; 0 excludes from promotion), then replication offset (most up-to-date data), then Run ID.
5. Forced Failover Test
# quit
redis-cli -h 192.168.1.21 -a MasterAuth!2026 debug sleep 30
# or
sudo systemctl stop redis-server # node1
# Sentinel
journalctl -u redis-sentinel -fIf you see a +switch-master mymaster 192.168.1.21 6379 192.168.1.22 6379 log line, the master has switched to node2. Manual failover is also possible.
redis-cli -p 26379 sentinel failover mymaster6. Client Integration
Applications must not hard-code the master IP. Use a Sentinel-aware client that queries Sentinel for the master address and then connects.
from redis.sentinel import Sentinel
sentinel = Sentinel(
[('192.168.1.21', 26379), ('192.168.1.22', 26379), ('192.168.1.23', 26379)],
socket_timeout=0.5,
sentinel_kwargs={'password': None},
)
master = sentinel.master_for('mymaster', password='MasterAuth!2026', socket_timeout=0.5)
replica = sentinel.slave_for('mymaster', password='MasterAuth!2026')
master.set('key', 'value')
print(replica.get('key'))Writes may fail for a short period immediately after failover. Applications must implement retry logic.
7. Operational Pitfalls
- min-replicas-to-write: Setting
min-replicas-to-write 1andmin-replicas-max-lag 10on the master refuses writes when all replicas are down, reducing split-brain data loss. - Don't put Sentinels on the same node: Prefer dedicated hosts. At minimum, place them so that one master going down does not take a Sentinel majority with it.
- Time synchronization (NTP): down-after decisions are timing-sensitive.
- Firewall: You must open both ports — 6379 (data) and 26379 (Sentinel).
Summary
| Item | Recommended value / approach |
|---|---|
| Sentinel count | Odd number (3 or more), on separate hosts |
| quorum | 3 Sentinels → 2 |
| down-after | Around 5000ms |
| Auth | Same requirepass + masterauth on every node |
| Preventing loss | min-replicas-to-write / max-lag |
| Client | Sentinel-aware + retries |
| Monitoring | journalctl, track +switch-master |
Sentinel prevents split-brain with two-stage consensus: quorum and majority election. Follow just these three practices — odd-numbered placement, consistent authentication, and Sentinel-aware clients — and you can run a stable single-master HA setup.
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Questions & answers
Ask a question about this guide. We'll review and reply.