Redis Master-Slave synchronization principle

Source: Internet
Author: User

Redis Master-Slave:

Role:

Enables real-time backup of data for Redis read-write separation and Redis high availability

Master-Slave synchronization principle:

One master one from the environment:

Environment: 2 Redis, one master one slave

1,master wait for command to enter

2,slave Connect master, send a sync command

3,master begins execution of Besave and uses the buffer to record the write command that was executed after Besave

4,slave side If a request comes in now, you can decide whether to continue using the current data to handle the client's request or to return an error to the client, depending on the configuration item.

5,master Besave executes, the slave sends the snapshot file, and the current write command is recorded in the buffer during the sending process.

6,slave Discard old data (if slave has data), start loading the snapshot file sent by master.

7,master The snapshot file is sent, start sending the write command inside the buffer period

8,slave after you have finished interpreting the snapshot file, start accepting the command request (client request) as usual.

After the command of the 9,master buffer is sent, the master does not perform a write operation from now on and sends the same command to the server.

10,slave executes the memory stored in the buffer command from the master server and accepts and executes every write command from the master server from now on

One master more from the environment:

Environment: Multiple Redis, one master multiple slave

When the new slave connection master has 2 different conditions

1, all slave simultaneously connected to master (step 5 has not been executed)

Execution process: All slave will accept the same snapshot file and the same buffer command

2, already have slave connection master (step 5,6 is executing or finished)

Execution process: The newly added slave will re-execute the above 10 steps


It is important to note that slave accepts a snapshot file of master to empty its data files, Redis does not support dual-master

Implementation steps:

It's just that the Redis synchronous setup is actually quite simple.

On the slave configuration file or redis_cli remote terminal

Slaveof <masterip> <masterport>
Masterauth <master-password> #认证密钥

This article from "Wang Xiao Acid" blog, reproduced please contact the author!

Redis Master-Slave synchronization principle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.