Redis Master-Slave synchronization principle-sync

Source: Internet
Author: User
Tags redis

Like the reason for MySQL master-slave replication, Redis reads and writes are particularly fast, but it can also produce a particularly high read pressure situation. In order to share the read pressure, Redis supports master-slave replication, and the master-slave structure of Redis can be a main multi-slave or cascade structure, and the graph below is a cascade structure.

Redis Master-slave replication can be divided into full-volume synchronization and incremental synchronization based on whether it is full. 1 Full-volume synchronization

Redis full replication typically occurs during the slave initialization phase, when slave needs to copy all the data on master. The steps are as follows:
1) connect the master server from the server and send the sync command;
2) After the master server receives the sync name, start executing the bgsave command to generate the Rdb file and use the buffer to record all the write commands executed thereafter;
3) After the master server Bgsave executes, send the snapshot files to all the slave servers, and continue to record the executed write commands during sending;
4) Discard all old data and load the received snapshot after receiving the snapshot file from the server;
5) After the primary server snapshot is sent, the write command to send the buffer to the slave server is started;
6) from the server to complete the loading of the snapshot, start receiving command requests, and execute to the autonomous server buffer write command;

After completing the previous steps, all the operations initiated from the server data are completed, and the server can now receive read requests from the user. 2 Incremental Synchronization

Redis incremental replication refers to the process of synchronizing a write operation that occurs on the primary server to the slave server when the slave starts to work correctly after initialization.
The process of incremental replication is primarily when the primary server executes a write command that sends the same write command to the server, receives and executes the received write command from the server. 3 Redis Master-Slave synchronization policy

When the master-slave has just connected, the whole volume is synchronized, and after the full synchronization, the incremental synchronization is done. Of course, slave can initiate a full-volume synchronization at any time if necessary. The Redis policy is that, in any case, an incremental synchronization will first be attempted, if not successful, requiring a full-volume synchronization from the machine. 4 Other

Redis 2.8 provides psync to optimize the efficiency of wire break re-connection
http://blog.csdn.net/sk199048/article/details/77922589 Reference:

[1] "Redis in ACTION"
[2] http://blog.csdn.net/houjixin/article/details/27680183
[3] http://daoluan.net/blog/2014/04/22/decode-redis-replication/

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.