Redis replication.
Primary / replica
Replica config:
replicaof primary.host 6379
masterauth password
replica-read-only yes
redis-cli REPLICAOF NO ONE # promote
redis-cli REPLICAOF host 6379 # demote
Async replication
Default. Eventual consistency. Primary doesn’t wait for replicas.
Replica reads
replica-read-only yes
Spread read load across replicas. Tolerate stale data.
WAIT command
WAIT 2 1000 # wait up to 1s for 2 replicas to ack
Gives “best effort” durability. Not synchronous.
INFO replication
INFO replication
# role:master
# connected_slaves:2
# slave0:ip=...,port=...,state=online,offset=...,lag=0
Sentinel (HA)
3+ Sentinel processes monitor primary; elect new primary on failure.
# sentinel.conf
sentinel monitor mymaster 10.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel parallel-syncs mymaster 1
redis-sentinel /etc/redis/sentinel.conf --port 26379
Clients discover primary via Sentinel:
from redis.sentinel import Sentinel
sentinel = Sentinel([("s1", 26379), ("s2", 26379), ("s3", 26379)])
master = sentinel.master_for("mymaster")
replica = sentinel.slave_for("mymaster")
Cluster (sharding + HA)
For horizontal scale + HA:
redis-cli --cluster create node1:6379 node2:6379 node3:6379 \
node4:6379 node5:6379 node6:6379 --cluster-replicas 1
16384 hash slots distributed across primaries. Each primary has a replica.
from redis.cluster import RedisCluster
client = RedisCluster(host="node1", port=6379)
Hash tags
SET {user:1}:profile ...
SET {user:1}:sessions ...
Same {...} → same slot → multi-key ops work.
Cross-region
Async replication across regions: stale reads possible. For strong consistency: avoid.
Common mistakes
- Treating replica as backup.
- No fencing → split brain.
- Sentinel running on same node as Redis it monitors.
- Replica drift from primary (lag).
- Cluster without hash tags then surprised multi-key ops fail.
Read this next
If you want my Sentinel + Cluster setup, it’s at rajpoot.dev .
Building something AI-, backend-, or data-heavy and want a second pair of eyes? I do consulting and freelance work — see my projects and ways to reach me at rajpoot.dev .