Skip to content

Redis Sentinel — high availability for single-shard Redis

Configure a three-node Sentinel deployment that monitors a primary-replica Redis pair, performs automatic failover, and lets clients discover the current primary.

Redis Sentinel is the open-source HA layer for non-clustered Redis — it monitors a primary and one or more replicas, detects primary failure, promotes a replica, and tells clients about the new primary. It is the right tool for single-shard workloads that need automatic failover; for multi-shard workloads, Redis Cluster is the alternative. This article walks the three-node Sentinel quorum that you actually want in production, the configuration that ties Sentinel to the Redis pair it monitors, and the client-discovery pattern that makes failover transparent to applications.

How to verify

# Sentinel processes running
sudo systemctl status redis-sentinel --no-pager

# Sentinel sees the master
redis-cli -p 26379 SENTINEL master mymaster

# Sentinel sees the replicas
redis-cli -p 26379 SENTINEL replicas mymaster
redis-cli -p 26379 SENTINEL sentinels mymaster

# Where Sentinel thinks the master is right now
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster

SENTINEL master mymaster returns dozens of fields; the important ones are flags (should include master, not s_down or o_down), num-slaves, num-other-sentinels, and quorum.

What’s happening

A Sentinel topology has three components:

  1. A Redis primary (writes accepted).
  2. One or more Redis replicas that replicate from the primary.
  3. Three or more Sentinel processes that observe the Redis pair and gossip among themselves.

Each Sentinel pings the primary periodically. If down-after-milliseconds (default 30 seconds) passes without a reply, the Sentinel marks the primary subjectively-down (s_down). When enough Sentinels (the quorum) agree, the primary is marked objectively-down (o_down). At that point the Sentinels elect a leader from among themselves, which then picks one of the replicas to promote.

After promotion, the new primary starts accepting writes; the old primary (if it comes back) is reconfigured as a replica; the Sentinels update their internal state; and on the next SENTINEL get-master-addr-by-name call, clients see the new primary’s address.

Three Sentinels is the minimum production count. With two, a network partition can leave both Sentinels unable to reach quorum (each is alone). With three, even after one Sentinel or one network domain fails, the remaining two can still agree.

The procedure

Assume the topology:

  • redis01 (10.0.0.5) — primary
  • redis02 (10.0.0.6) — replica
  • redis03 (10.0.0.7) — replica AND a Sentinel
  • redis01, redis02 also run Sentinels
  1. Start with a working Redis primary-replica pair. On redis02 and redis03, configure as replicas in /etc/redis/redis.conf:

    replicaof 10.0.0.5 6379
    masterauth strong-password
    requirepass strong-password

    Restart and verify with redis-cli -a strong-password INFO replication — role:slave on the replicas, role:master on the primary.

  2. Install Sentinel (ships with Redis on Ubuntu).

    sudo apt install -y redis-sentinel
  3. Configure /etc/redis/sentinel.conf identically on all three Sentinel hosts.

    port 26379
    bind 127.0.0.1 10.0.0.5    # this host's private IP
    sentinel monitor mymaster 10.0.0.5 6379 2
    sentinel auth-pass mymaster strong-password
    sentinel down-after-milliseconds mymaster 10000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 60000
    sentinel deny-scripts-reconfig yes
    logfile /var/log/redis/sentinel.log
    dir /var/lib/redis-sentinel

    The 2 at the end of sentinel monitor is the quorum — the number of Sentinels that must agree the primary is down before failover.

  4. Set ACLs or requirepass consistently. Sentinels need to authenticate to Redis with auth-pass. Modern Sentinel (6.2+) also requires its own password for inter-Sentinel auth:

    requirepass <sentinel-password>
    sentinel sentinel-pass mymaster <sentinel-password>
  5. Start Sentinels on all three hosts.

    sudo systemctl enable --now redis-sentinel
    sudo systemctl status redis-sentinel --no-pager
    sudo tail -20 /var/log/redis/sentinel.log
  6. Verify the topology is recognized.

    redis-cli -p 26379 SENTINEL master mymaster
    redis-cli -p 26379 SENTINEL replicas mymaster
    redis-cli -p 26379 SENTINEL sentinels mymaster

    num-other-sentinels should be 2 (the other two Sentinels seen by this one).

  7. Test failover. Kill the primary’s Redis (not Sentinel).

    sudo systemctl stop redis-server   # on redis01

    On any Sentinel, watch the failover happen (about 10-15 seconds):

    sudo tail -f /var/log/redis/sentinel.log

    Then query the new master:

    redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
    # Returns the new primary's IP:port

    Bring the old primary back; it rejoins as a replica.

  8. Configure clients for Sentinel-aware discovery. Most modern clients support this — examples:

    • Python (redis-py): Sentinel([('redis01', 26379), ('redis02', 26379), ('redis03', 26379)], password='...').master_for('mymaster')
    • Node (ioredis): new Redis({ sentinels: [{host:'redis01',port:26379}, ...], name: 'mymaster' })
    • Java (Jedis): JedisSentinelPool('mymaster', sentinels, ...)
    • Go (go-redis): redis.NewFailoverClient(&redis.FailoverOptions{MasterName: 'mymaster', SentinelAddrs: ...})

    The client connects to the Sentinels first, gets the current master, and reconnects there. On failover, the client transparently switches.

  9. Operator best practice — never CONFIG SET directly on the master. Sentinel manages replica reconfiguration; manual replicaof commands or CONFIG SET can confuse it. Apply changes via SENTINEL set or by editing sentinel.conf and restarting Sentinel.

Common pitfalls

  • Quorum = 2 with only 2 Sentinels never reaches quorum if either goes down. Always run an odd number of Sentinels, with quorum set to a majority (3 Sentinels → quorum 2; 5 Sentinels → quorum 3).
  • Sentinel and the Redis it monitors on the same host means one host failure takes out both. Run Sentinels on the same hosts as Redis if you have only three hosts, but ensure those three hosts are in different failure domains.
  • Clients that cache the master address bypass Sentinel after the initial discovery — make sure your client uses Sentinel-aware reconnect (or has a short connection lifetime).
  • After a failover, the old master rejoins as a replica with its old credentials — if you rotated masterauth between failover and recovery, the old master cannot replicate until you fix the password.
  • Sentinel does not split partition data — if you need sharding, use Redis Cluster (a different topology). Sentinel + replication is single-shard HA only.

In the engagements we run, single-shard Redis with Sentinel is our default HA pattern for caching and session-store workloads up to a couple hundred GB. For sharded workloads we use Redis Cluster or a managed service. We monitor Sentinel quorum, primary uptime, and replication lag, with alerts on failover events and on quorum loss. Operated under Managed Operations — and the broader HA design lives under Clustered Environments.