Home > Database > Redis > body text

How to synchronize redis cluster

(*-*)浩
Release: 2019-11-22 09:51:14
Original
4919 people have browsed it

How to synchronize redis cluster

Master-slave replication:

1. The replication function of redis is to support data synchronization between multiple databases. One is the master database (master) and the other is the slave database (slave). The master database can perform read and write operations. When a write operation occurs, the data will be automatically synchronized to the slave database, while the slave database is generally read-only. , and receive data synchronized from the master database. A master database can have multiple slave databases, while a slave database can only have one master database. (Recommended study: Redis video tutorial)

2. Through the replication function of redis, the read and write separation of the database can be well realized and the load capacity of the server can be improved. The master database mainly performs write operations, while the slave database is responsible for read operations.

The summary of the working principle of Redis replication is as follows:

1. If a Slave is set up, whether it is the first connection or reconnection to the Master, it A SYNC command will be issued;

2. When the Master receives the SYNC command, it will do two things:

a) The Master executes BGSAVE, which saves the data to disk in the background (rdb snapshot file);

b) Master simultaneously stores the newly received commands for writing and modifying the data set into the buffer (non-query type);

3. When the Master writes the data in the background After saving to the snapshot file, the Master will transfer the snapshot file to the Slave, and the Slave will clear the memory and load the file into the memory;

4. The Master will also collect the previously collected data into the buffer. The commands in are forwarded to the Slave through the Reids command protocol, and the Slave executes these commands to achieve synchronization with the Master;

5. The Master/Slave will continue to synchronize the commands asynchronously to achieve the final data Synchronization is consistent;

6. It should be noted that once a reconnection occurs between the Master and Slave, a full synchronization operation will be triggered. But in versions after 2.8, it may also be a partial synchronization operation.

For more Redis-related technical articles, please visit the Introduction to Using Redis Database Tutorial column to learn!

The above is the detailed content of How to synchronize redis cluster. 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