Redis Replication (High availability Networksetup)

Master / Slave Replication

First Server instance

 redis-server --port 6379 --dbfilename db1.rdb

Second Server instance

redis-server --port 6380 --dbfilename db2.rdb

Connect to 1st Server instance

Connect to 2nd Server instance

Now let us convert the second server into a replica

2nd Server CLI – Hit command replicaof

1st Server CLI again checked the replication id to check if it matches the server

Below changes are observed in the console of 2nd Redis Server

Checking if the 2nd Server (replica) CLI has the same keys as Master

Replication Example (TMUX used just to display side by side)

  • Write on replica fails since it is read only

How to stop replication ?

#Connect to the replication server via CLI
#Enter below command
replicaof no one
#Connect to the master server via CLI
#Check the number of slaves via command "INFO REPLICAION"

How to check if replication is happening or not ?

  • The replica offset should increase for the slave everytime data is inserted into the master

Leave a Comment