Home  >  Article  >  Database  >  How to ensure data consistency among nodes in redis cluster

How to ensure data consistency among nodes in redis cluster

(*-*)浩
(*-*)浩Original
2019-11-20 14:16:357217browse

How to ensure data consistency among nodes in redis cluster

In order to ensure that the cluster can still operate normally even when some nodes are offline or unable to communicate with most nodes in the cluster.

Redis cluster uses the master-slave replication function for nodes: Each node in the cluster has 1 to N replicas (replica), one of which is the master node ( master), and the remaining N-1 replicas are slave nodes. (Recommended learning: Redis video tutorial)

Several common methods of Redis master-slave replication

One master and two slaves A(B, C) One Master and two Slaves

passing on from generation to generation (decentralization) A - B - C, B is both the master node (C's master node) and a slave node (A's slave node)

Anti-customer-based (after the master node goes down, manually upgrade the slave node to the master node) & Sentinel mode (after the master node goes down, automatically upgrade the slave node to the master node)

Master-slave Replication:

1, The replication function of redis supports 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 is automatically synchronized to the slave database. The slave database is generally read-only and receives Data synchronized from the master database, a master database can have multiple slave databases, and a slave database can only have one master database.

2. The replication function of redis can effectively separate the reading and writing of the database and improve the load capacity of the server. The master database mainly performs write operations, while the slave database is responsible for read operations.

1: When a slave database starts, it will send a sync command to the primary database.

2: After receiving the sync command, the primary database will start saving snapshots in the background (performing RDB operations). And cache the commands received during the save period

3: When the snapshot is completed, redis will send the snapshot file and all cached commands to the slave database.

4: After receiving it from the database, it will load the snapshot file and execute the received cached command

The above is the detailed content of How to ensure data consistency among nodes in redis cluster. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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