O'Reilly logo

Redis 4.x Cookbook by Zuofei Wang, Pengcheng Huang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required