Different from master-salve or sentinel mode, the biggest difference between cluster and them is that the first two are full storage, which consumes a lot of memory and has a barrel effect, while the cluster cluster is distributed storage, that is, each Redis stores different content.
redis-cluster is designed to have a total of 16384 hash slots available, and each master is allocated a part of the slot. The distribution algorithm is: [hash_slot = crc16(key) mod 16384] If there is {}, take the available key of {}, otherwise the entire key can be available. The cluster must have at least 3 masters and 3 slaves, and each instance uses a different configuration file.
All redis nodes are interconnected with each other (PING-PONG mechanism), and the binary protocol is used internally to optimize transmission speed and bandwidth.
The fail of a node takes effect only when more than half of the nodes in the cluster detect failures.
The client is directly connected to the redis node, without the need for an intermediate proxy layer. The client does not need to connect to all nodes in the cluster, just connect to any available node in the cluster.
redis-cluster maps all physical nodes to [0-16383] slot, and cluster is responsible for maintaining nodeslotvalue
redis-cluster voting: fault tolerance
1. The voting process involves all masters in the cluster. If more than half of the master nodes communicate with the master node over time (cluster-node-timeout), the current master is considered The node hangs up.
2. When does the entire cluster become unavailable (cluster_state:fail)?
If any master in the cluster hangs up, and the current master has no slave, and the cluster enters the fail state, it can also It is understood that when the slot mapping [0-16383] of the cluster is incomplete, it enters the fail state.
redis-3.0.0.rc1 adds the cluster-require-full-coverage parameter, which is turned off by default, and fails to open the cluster compatibility part.
If more than half of the masters in the cluster die, regardless of whether there is a slave or not, the cluster will enter the fail state.
In the redis-cluster architecture, the redis-master node is generally used to receive reads and writes, while the redis-slave node is generally only used for backup. It has the same slot set as the corresponding master. If a If redis-master fails unexpectedly, its corresponding slave will be upgraded to a temporary redis-master.
In the official redis documentation, there is a description of the redis-cluster architecture: Under the cluster architecture, by default, redis-master is generally used to receive reads and writes, while redis-slave is used to Backup, when a request is made to the slave, it will be directly redirected to the master where the corresponding key is located for processing.
But if you don’t mind reading potentially expired data in redis-cluster and are not interested in write requests, you can also set the slave to readable through the readonly command, and then obtain the relevant information through the slave. The key achieves the separation of reading and writing.
For more redis knowledge, please pay attention to theredis introductory tutorialcolumn.
The above is the detailed content of Introduction to redis cluster cluster. For more information, please follow other related articles on the PHP Chinese website!