High availability with Redis Sentinel + Cluster
Symptom
Goal: set up a master-replica deployment with automatic failover for Redis using Sentinel; switch to Redis Cluster mode if horizontal scaling is needed.
1. Configure the master and replicas
Run one master and at least two replicas. Replicas follow the master with REPLICAOF ('replicaof <host> <port>' can also be written in redis.conf). Enable AOF or RDB for persistence; authentication with requirepass/masterauth is recommended.
Redis
# at runtime on the replica nodes:
REPLICAOF 10.0.0.10 6379
# to make it persistent, redis.conf:
# replicaof 10.0.0.10 6379
# masterauth secret
INFO replication2. Configure Sentinel with monitor and quorum
Define the master to monitor and the quorum in each Sentinel node's sentinel.conf. quorum is the minimum number of Sentinels required to consider the master 'down'. In production, 3 Sentinels on 3 separate servers are recommended (against split-brain).
Redis
# sentinel.conf:
sentinel monitor mymaster 10.0.0.10 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 13. Start the Sentinel processes
Start Sentinel on each node. Sentinels automatically discover each other and the replicas; they write the configuration to the file at runtime. Therefore sentinel.conf must be writable.
Redis
redis-sentinel /etc/redis/sentinel.conf
# or:
redis-server /etc/redis/sentinel.conf --sentinel4. Query status through Sentinel and test failover
Query the current master and replicas with SENTINEL commands. Applications should learn the current master by asking Sentinel 'get-master-addr-by-name'. Verify automatic switchover with a planned failover.
Redis
SENTINEL master mymaster
SENTINEL get-master-addr-by-name mymaster
SENTINEL replicas mymaster
# planned switchover:
SENTINEL failover mymaster5. Alternative: partition the data with Redis Cluster
If a single master's memory/throughput is not enough, use Redis Cluster: data is split into 16384 hash slots and distributed across multiple masters; each master has its own replica. The application must use a cluster-aware client. Set it up with redis-cli --cluster create.
Redis
redis-cli --cluster create \
10.0.0.11:6379 10.0.0.12:6379 10.0.0.13:6379 \
10.0.0.21:6379 10.0.0.22:6379 10.0.0.23:6379 \
--cluster-replicas 16. Verify cluster state
After the cluster is created, verify that all slots are assigned and the nodes are connected. cluster_state should be 'ok' and all 16384 slots should appear assigned. Monitor node and slot distribution with CLUSTER commands.
Redis
redis-cli --cluster check 10.0.0.11:6379
redis-cli -c -h 10.0.0.11 CLUSTER INFO
redis-cli -c -h 10.0.0.11 CLUSTER NODES