How does Redis replication work?
Answer
Redis replication uses a primary-replica (formerly master-slave) model. A replica connects to a primary with REPLICAOF primary-ip port. On initial sync, the primary forks, saves an RDB snapshot, and sends it to the replica, which loads it. After that, the primary sends a stream of write commands to the replica in real time. Replication is asynchronous by default — the primary doesn't wait for replicas to confirm writes before responding to clients. This means replicas can lag behind the primary. WAIT numreplicas timeout blocks until at least N replicas have acknowledged all previous writes. Replicas are read-only by default, offloading read traffic from the primary. One primary can have multiple replicas, and replicas can themselves have sub-replicas, forming a tree topology for large-scale read distribution.
More Redis Questions
View all →- Intermediate What is Redis Cluster and how does it shard data?
- Intermediate What is the difference between Redis Sentinel and Redis Cluster?
- Intermediate How do MULTI and EXEC work in Redis transactions?
- Intermediate What is WATCH and optimistic locking in Redis?
- Intermediate What is Lua scripting in Redis and when should you use it?