Implementing Replication

1. Configuring Master Server

DirectiveDescription
requirepassSet master password
masterauthUsed when promoted to replica
repl-backlog-size 64mbBuffer for partial resync

2. Configuring Replica Server

replicaof master.host 6379
masterauth secret
replica-read-only yes
CommandDescription
REPLICAOF host portRuntime configure replication
REPLICAOF NO ONEDetach and become master

3. Setting Replica Read-Only

DirectiveDefault
replica-read-only yesReject writes (recommended)

4. Checking Replication Status

CommandReturns
INFO replicationRole, connected replicas, offsets
ROLEmaster/slave/sentinel with details

5. Promoting Replica to Master

CommandDescription
REPLICAOF NO ONEManual promotion
SentinelAutomatic on failover

6. Configuring Diskless Replication

DirectiveEffect
repl-diskless-sync yesStream RDB over socket without intermediate file
repl-diskless-sync-delay 5Wait to batch replicas
repl-diskless-load on-empty-dbReplica loads from socket without disk

7. Setting Replication Timeout

DirectiveDefault
repl-timeout 60Seconds before disconnect
repl-ping-replica-period 10Keepalive interval

8. Enabling Partial Resync

DirectiveDetail
repl-backlog-sizeSize of replication ring buffer
repl-backlog-ttlDrop backlog after N seconds of no replicas

9. Using WAIT for Synchronous Replication

CommandReturns
WAIT numreplicas timeout-msNumber of replicas that ACK'd

10. Using WAITAOF for AOF Sync

CommandDescription
WAITAOF numlocal numreplicas timeout-msWait for AOF fsync on local + N replicas 7.2+

11. Handling Replication Lag

MetricSource
master_repl_offset − slave_repl_offsetINFO replication
lag (seconds)Per-replica in master INFO

12. Monitoring Replication Offset

FieldDetail
master_replidReplication group ID
repl_backlog_active1 if backlog enabled

13. Using Replicas for Read Scaling

PatternDetail
Read from replicasUse READONLY in Cluster context
Eventual consistencyReads may lag master
min-replicas-to-write nRefuse writes if too few replicas online