How to do it...

The steps for optimizing replication are as follows:

  1. Open a console and switch the current user to root. Then set some variables in the console for the basic information of a master and slave:
$ M_IP=127.0.0.1 
$ M_PORT=6379 
$ M_RDB_NAME=master.rdb 
$ M_OUT=master.out 
$ S1_IP=127.0.0.2 
$ S1_PORT=6380 
$ S1_OUT=slave_1.out 
$ S1_RDB_NAME=slave_1.rdb 
  1. Start the two Redis instances:
$ nohup /redis/bin/redis-server --port $M_PORT --bind $M_IP --dbfilename $M_RDB_NAME > $M_OUT & 
$ nohup /redis/bin/redis-server --port $S1_PORT --bind $S1_IP --dbfilename $S1_RDB_NAME  > $S1_OUT& 
  1. Sleep for a while to wait for the Redis instances to finish their startup. After the sleep, we set some sample data to one of the Redis instances:
$ sleep ...

Get Redis 4.x Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.