Home  >  Article  >  Database  >  Redis master-slave replication creation process

Redis master-slave replication creation process

尚
forward
2020-04-06 09:03:131788browse

Redis master-slave replication creation process

First we will add slaveof masterHost masterPort to the slave library configuration file to specify the corresponding master library. If you start the slave library at this time, then redis will find the specified IP and port number to connect to the master; if it is a running redis server, then we can execute the slaveof masterHost masterPort command to start replicating from the slave library.

The following table shows the steps that redis goes through during master-slave replication:

Steps Master server Slave server
1 Normal operation... Send sync command to connect to the main server
2 Execute the bgsave command and record subsequent write commands to the buffer If slave is configured -serve-stale-data is yes (default setting), the slave library will continue to respond to client requests; otherwise, any request other than INFO and SLAVOF commands will return an error message to the client
3 bgsaveAfter execution, send the snapshot file to the slave library, and continue to use the buffer to record write commands during this period Discard all data , load the snapshot file of the main library
4 After the snapshot is sent, start sending the write command in the buffer mentioned before Complete the interpretation operation of the snapshot and start to receive command requests normally
5 The buffer content is sent. From now on, every time a command is executed, it will be sent from the server The same command executes the command in the buffer sent by the main library. After the execution is completed, receive and execute each write command sent by the main library

It should be noted that when the slave library starts to copy, it will first clear its own data.

For more redis knowledge, please pay attention to the redis introductory tutorial column.

The above is the detailed content of Redis master-slave replication creation process. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete