Home > Database > Redis > How to implement incremental synchronization of redis

How to implement incremental synchronization of redis

(*-*)浩
Release: 2019-11-27 09:49:31
Original
3741 people have browsed it

How to implement incremental synchronization of redis

Redis’ existing synchronization strategy

1. Incremental synchronization functional components (Recommended learning: Redis video tutorial)

1) The replication offset of the master server and the replication offset of the slave server;

The master server propagates N bytes to the slave server each time When receiving data, it adds N to the value of its own replication offset;

Every time the slave server receives N bytes of data transmitted from the master server, it adds its own replication offset. Add N to the shift value.

2) The replication backlog buffer of the main server;

A fixed-length queue maintained by the main server, the default is 1M, when the main server performs command propagation, it will not only send the write command For all slave servers, write commands will also be queued into the replication backlog buffer.

3) The running ID of the server.

Each server randomly generates a running ID (runid) when it starts.

2. Incremental synchronization implementation

1) The slave server sends the PSYNC command to the master server, carrying the runid and replication offset of the master server;

2) The main server verifies whether the runid is consistent with its own runid. If it is inconsistent, a full copy is performed;

3) The main server verifies whether the copy offset is within the backlog buffer. If not, a full copy is performed. Copy;

4) If both verifications pass, the master server will send all the data after the offset in the backlog area to the slave server, and the master and slave servers will return to a consistent state again.

3. Conclusion

1) Only when the runid and offset of the master server carried by the slave server are consistent, Redis will adopt the incremental synchronization strategy. There is Great limitations;

2) Therefore, redis will adopt a full synchronization strategy when the slave server is restarted, the master server is replaced, or the connection time is too long.

For more Redis-related technical articles, please visit the Redis Getting Started Tutorial column to learn!

The above is the detailed content of How to implement incremental synchronization of redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template