Implementing Replication
1. Configuring Master Server
| Directive | Description |
|---|---|
requirepass | Set master password |
masterauth | Used when promoted to replica |
repl-backlog-size 64mb | Buffer for partial resync |
2. Configuring Replica Server
replicaof master.host 6379
masterauth secret
replica-read-only yes
| Command | Description |
|---|---|
REPLICAOF host port | Runtime configure replication |
REPLICAOF NO ONE | Detach and become master |
3. Setting Replica Read-Only
| Directive | Default |
|---|---|
replica-read-only yes | Reject writes (recommended) |
4. Checking Replication Status
| Command | Returns |
|---|---|
INFO replication | Role, connected replicas, offsets |
ROLE | master/slave/sentinel with details |
5. Promoting Replica to Master
| Command | Description |
|---|---|
REPLICAOF NO ONE | Manual promotion |
| Sentinel | Automatic on failover |
6. Configuring Diskless Replication
| Directive | Effect |
|---|---|
repl-diskless-sync yes | Stream RDB over socket without intermediate file |
repl-diskless-sync-delay 5 | Wait to batch replicas |
repl-diskless-load on-empty-db | Replica loads from socket without disk |
7. Setting Replication Timeout
| Directive | Default |
|---|---|
repl-timeout 60 | Seconds before disconnect |
repl-ping-replica-period 10 | Keepalive interval |
8. Enabling Partial Resync
| Directive | Detail |
|---|---|
repl-backlog-size | Size of replication ring buffer |
repl-backlog-ttl | Drop backlog after N seconds of no replicas |
9. Using WAIT for Synchronous Replication
| Command | Returns |
|---|---|
WAIT numreplicas timeout-ms | Number of replicas that ACK'd |
10. Using WAITAOF for AOF Sync
| Command | Description |
|---|---|
WAITAOF numlocal numreplicas timeout-ms | Wait for AOF fsync on local + N replicas 7.2+ |
11. Handling Replication Lag
| Metric | Source |
|---|---|
| master_repl_offset − slave_repl_offset | INFO replication |
| lag (seconds) | Per-replica in master INFO |
12. Monitoring Replication Offset
| Field | Detail |
|---|---|
| master_replid | Replication group ID |
| repl_backlog_active | 1 if backlog enabled |
13. Using Replicas for Read Scaling
| Pattern | Detail |
|---|---|
| Read from replicas | Use READONLY in Cluster context |
| Eventual consistency | Reads may lag master |
min-replicas-to-write n | Refuse writes if too few replicas online |