Home/Engineer/Databases/Redis Sentinel — High Availa…
DatabasesAdvancedlinuxredissentinelha

Redis Sentinel — High Availability and Automatic Failover Setup

Configure Redis Sentinel for master-replica monitoring, automatic failover, and service discovery. A hands-on walkthrough of quorum behavior, client integration, and operational pitfalls.

Contents
  1. What is Redis Sentinel?
  2. Recommended Topology
  3. 1. Redis Replication Setup
  4. 2. Sentinel Configuration
  5. 3. Verify Operation
  6. 4. SDOWN and ODOWN — Failover Decision Flow
  7. 5. Forced Failover Test
  8. 6. Client Integration
  9. 7. Operational Pitfalls
  10. Summary

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.


The most common setup is 1 master + 2 replicas + 3 Sentinels.

NodeIPRole
node1192.168.1.21Redis Master + Sentinel
node2192.168.1.22Redis Replica + Sentinel
node3192.168.1.23Redis 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:

Config
bind 0.0.0.0 -::1
port 6379
requirepass MasterAuth!2026
masterauth MasterAuth!2026
appendonly yes

Replica (node2, node3) redis.conf:

Config
bind 0.0.0.0 -::1
port 6379
requirepass MasterAuth!2026
masterauth MasterAuth!2026
replicaof 192.168.1.21 6379
appendonly yes

Set 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:

Bash
redis-cli -a MasterAuth!2026 info replication
CODE
# 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:

Config
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 60000

quorum 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:

Bash
redis-sentinel /etc/redis/sentinel.conf
# or systemd
sudo systemctl enable --now redis-sentinel

3. Verify Operation

Bash
redis-cli -p 26379 sentinel master mymaster
redis-cli -p 26379 sentinel replicas mymaster
redis-cli -p 26379 sentinel sentinels mymaster

To quickly query only the current master address:

Bash
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

StageAbbreviationMeaning
Subjective downSDOWNOne Sentinel judges the master unresponsive
Objective downODOWNA 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

Bash
# 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 -f

If 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.

Bash
redis-cli -p 26379 sentinel failover mymaster

6. 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.

Python
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 1 and min-replicas-max-lag 10 on 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

ItemRecommended value / approach
Sentinel countOdd number (3 or more), on separate hosts
quorum3 Sentinels → 2
down-afterAround 5000ms
AuthSame requirepass + masterauth on every node
Preventing lossmin-replicas-to-write / max-lag
ClientSentinel-aware + retries
Monitoringjournalctl, 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.

#redis#sentinel#ha#failover
Editorial note

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

Topic-related official docs (auto-linked · not per-claim sources)Redis documentation ↗

Questions & answers

Ask a question about this guide. We'll review and reply.