Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to synchronize redis Cluster data

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to synchronize redis cluster data, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

Redis does not have the concept of replication location like mysql, so when Slave and Master are disconnected and then reconnected, all snapshots of Master will be taken, all data of Slave will be erased, and the entire memory table will be re-established, which causes Salve to recover data very slowly and puts pressure on Master.

The master-slave replication strategy of Redis is realized through its persistent rdb files. The process is to dump out rdb files, transfer all rdb files to slave, and then synchronize the operations after dump to slave in real time. Make the slave server (slave server) an exact replica of the master server (master server). The following features are mentioned in the official document ReplicationHowto:

A master supports multiple slave,slave to accept connections from other slave as master for other slave, thus forming a multilevel replication function of master-slave without blocking the master server: the master server can continue to process command requests even if one or more slave servers are synchronizing for the first time. Replication does not block the slave server: as long as the appropriate settings are made in the redis.conf file, the server can use the old version of the dataset to handle command queries, even if the slave server is in the process of initial synchronization. However, connection requests are blocked during the period of time when the old version of the dataset is deleted from the server and the new version is loaded. Replication is used to provide scalability, for example, the slave side can be used as data redundancy, time-consuming commands (such as sort) can be sent to some slave to avoid master blocking, or slave can be used for persistence, which can be performed by the slave server, which only needs to comment out the save instructions in the master configuration file.

Redis uses asynchronous replication.

Master-slave replication of Redis is divided into two phases:

1) synchronization operation: update the database state of the slave server to the current database state of the master server.

2) Command propagation: when the database state of the master server is modified, resulting in inconsistencies in the database state of the master and slave servers, let the master and slave servers return to a consistent state.

Synchronization

When the client sends a SLAVEOF command to the slave server, requiring the slave server to copy the master server, the slave server first needs to perform a synchronization operation, that is, to update the database state of the slave server to the current database state of the master server.

The synchronization from the slave server to the master server needs to be accomplished by sending the SYNC command to the master server. Here are the steps to execute the SYNC command:

Send SYNC commands from the server to the master server. The primary server that receives the SYNC command executes the BGSAVE command, generates an RDB file in the background, and uses a buffer to record all write commands executed from now on. When the BGSAVE command of the master server is finished, the master server will send the RDB file generated by the BGSAVE command to the slave server, receive and load the RDB file from the server, and update its database status to the database state of the master server when the BGSAVE command is executed. The master server sends all write commands recorded in the buffer to the slave server, and executes these write commands from the slave server to update its database state to the current state of the master server database.

Thank you for reading this article carefully. I hope it will be helpful for everyone to share how to synchronize redis cluster data. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you have any problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report