CLI Testing
1. Check Replication Status
- On the Master:
redis-cli -h <master_host> -p <master_port> INFO REPLICATION
- Look for
connected_slaves
. It should list all connected replicas with their IP addresses and ports.
- On the Replica:
redis-cli -h <replica_host> -p <replica_port> INFO REPLICATION
- Verify
role:slave
,master_host
,master_port
, and thatslave_read_only
is set to1
.
2. Monitor Replication Lag
- On the Master:
redis-cli -h <master_host> -p <master_port> INFO REPLICATION
- Note the
master_repl_offset
.
- On the Replica:
redis-cli -h <replica_host> -p <replica_port> INFO REPLICATION
- Note the
slave_repl_offset
. - Calculate the difference between
master_repl_offset
andslave_repl_offset
. A small difference indicates low lag.
3. Test Data Consistency
- Set a Key on the Master:
redis-cli -h <master_host> -p <master_port> SET mykey "value"
- Get the Key on the Replica:
redis-cli -h <replica_host> -p <replica_port> GET mykey
- Verify that the value retrieved from the replica matches the value set on the master.
4. Force a Resync (for testing)
- On the Replica:
redis-cli -h <replica_host> -p <replica_port> SLAVEOF NO ONE
redis-cli -h <replica_host> -p <replica_port> SLAVEOF <master_host> <master_port>
Key Considerations:
- Frequency: Regularly run these checks to monitor replication health.
- Scripting: Create scripts to automate these checks and generate reports.
- Alerting: Set up alerts based on replication lag thresholds.