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

The method of realizing incremental synchronization of redis

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article will explain in detail the methods to achieve incremental synchronization of redis. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. The concept of incremental synchronization

Incremental synchronization means that when the master server has a data update, it will be synchronized to all slave servers immediately.

When we add or subtract data from the master server, the replicationFeedSalves () function is triggered, and each subsequent command called on the Master server uses the replicationFeedSlaves () function to synchronize to the Slave server. Of course, before executing this function, the master server will determine whether the command executed by the user has a data update, and if there is a data update and the slave server is not empty, it will execute this function, and the main job of this function is to send the commands executed by the user to all slave servers and let the slave server execute, so that the synchronization function can be implemented.

2. Components of incremental synchronization function

1) replication offset of master server and replication offset of slave server

Each time the master server propagates N bytes of data to the slave server, it adds N to its own replication offset.

Each time the slave server receives N bytes of data transmitted from the master server, add N to the value of its own replication offset.

2) replication backlog buffer of the primary server

A fixed-length queue maintained by the master server, which defaults to 1m. When the master server propagates commands, it not only sends write commands to all slave servers, but also queues write commands into the replication backlog buffer.

3) running ID of the server.

Each server randomly generates and runs ID (runid) at startup.

3. Implementation of incremental synchronization

1) send the PSYNC command from the server to the master server with the runid and replication offset of the master server

2) the master server verifies that the runid is consistent with its own runid, and if it is inconsistent, it will make a full copy.

3) the master server verifies whether the replication offset is in the backlog buffer, and if not, make a full copy

4) if all the verification is passed, the master server will send all the data after the offset in the backlog area to the slave server, and the master and slave server will return to the consistent state again.

4. Conclusion

1) only when the master server runid and offset carried by the slave server match, Redis will adopt the strategy of incremental synchronization, which has great limitations.

2) therefore, redis will adopt the strategy of full synchronization when the slave server is restarted, the master server is replaced, and the disconnection is too long.

On the realization of redis incremental synchronization methods to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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