Redis master-slave synchronization principle-SYNC, redis master-slave principle-sync

Source: Internet
Author: User

Principle of Redis master-slave synchronization-SYNC [Switch], principle of redis master-slave-sync

Similar to the reason for MySQL master-slave replication, although Redis reads and writes fast, it also produces a particularly high read pressure. To share the read pressure, Redis supports master-slave replication. The master-slave structure of Redis can adopt a master-slave multi-slave or cascade structure, which is a cascade structure.
 
Redis master-slave replication can be divided into full synchronization and incremental synchronization based on whether or not it is full.

1. Full Synchronization

Full Redis replication usually occurs in the Slave initialization phase. In this case, Slave needs to copy all the data on the Master. The procedure is as follows:
1) connect to the master server from the server and send the SYNC command;
2) After receiving the SYNC name, the master server starts to execute the BGSAVE command to generate the RDB file and use the buffer to record all the subsequent write commands;
3) after the master server BGSAVE is executed, it sends the snapshot file to all slave servers and records the executed write commands during the sending process;
4) after the server receives the snapshot file, it discards all old data and loads the received snapshot;
5) after the master server snapshot is sent, the write command in the buffer zone is sent to the slave server;
6) The server loads snapshots, receives command requests, and executes write commands in the autonomous Server Buffer Zone;
 
After completing the preceding steps, all operations on data initialization from the slave server are completed. The slave server can now receive read requests from users.

2. incremental Synchronization

Redis incremental replication refers to the process of synchronizing write operations on the master server to the Slave server when the Slave starts to work normally after initialization.
The incremental replication process is mainly because each time the master server executes a write command, the master server sends the same write command to the slave server to receive and execute the received write command.

3. Redis master-slave synchronization Policy

When the master and slave nodes are connected, perform full synchronization. After the full synchronization ends, perform incremental synchronization. Of course, if necessary, slave can initiate full synchronization at any time. The redis policy is that, in any case, incremental synchronization is first attempted. If it fails, full synchronization is required from the machine.

4 others

Redis 2.8 and later provide PSYNC to optimize the efficiency of reconnection
Http://www.cnblogs.com/JeremyWYL/p/8482736.html

Reprinted: http://blog.csdn.net/sk199048/article/details/50725369

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.