How to realize Master-Slave synchronization in redis
How does redis achieve master-slave synchronization? In response to this problem, today Xiaobian summarized this article, hoping to help more friends who want to solve this problem find a simpler and easier way.
Redis master-slave replication can be divided into full synchronization and incremental synchronization according to whether it is full.
1 Total synchronization
The full synchronization process of Redis is mainly divided into three stages:
Synchronous snapshot phase: Master creates and sends snapshot to Slave,Slave loads and parses snapshot. The Master also stores new write commands generated during this phase into the buffer.
Synchronous write buffer phase: Master synchronizes write commands stored in buffer to Slave.
Synchronous increment phase: Master writes synchronous operation commands to Slave.
After completing the above steps, all operations of data initialization from the server are completed, and the slave server can now receive read requests from users.
2 incremental synchronization
Redis incremental synchronization mainly refers to the process of synchronizing the write operations of the Master to the Slave when the Slave starts working normally after initialization. Typically, every time a Master executes a write command, it sends the same write command to the Slave, which then receives and executes it.
3 Redis master-slave synchronization strategy
When the master and slave are just connected, full synchronization is performed; after full synchronization is completed, incremental synchronization is performed. Of course, slaves can initiate full synchronization at any time if needed. The redis strategy is to try incremental synchronization first anyway, and if unsuccessful, require full synchronization from the slave.
About redis to achieve master-slave synchronization scheme to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.