In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of the principle of redis cluster, which is very detailed and has certain reference value. Friends who are interested must finish it!
The principle of redis Cluster
If you can rely on sentinels to achieve high availability of redis, if you still want to support high concurrency while accommodating large amounts of data, you need a redis cluster. Redis cluster is a distributed data storage scheme provided by redis. Cluster shares data through data slicing sharding and provides replication and failover functions.
Node
A redis cluster consists of multiple node node, and multiple node are connected by the cluster meet command. The handshake process of the node:
Node A receives a cluster meet command from the client
A sends a meet message to B based on the IP address and port number received
Node B receives the meet message and returns pong.
A knows that B has received a meet message and returns a ping message. The handshake is successful.
Finally, node A will propagate the information of node B to other nodes in the cluster through the gossip protocol, and other nodes will also shake hands with B.
Slot slot
Redis stores data in the form of cluster fragmentation. The entire cluster database is divided into 16384 slot. Each node in the cluster can handle 0-16384 slot. When there are 16384 slot nodes in the database, the cluster is online. On the contrary, as long as one slot is not processed, the offline state will be processed. The slot can be assigned to the corresponding node for processing through the cluster addslots command.
Slot is an array of bits. The length of the array is 16384. 8. 2048, and each bit of the array is processed by the node by 1. 0 means not processed. As shown in the figure, node A processes the slot of 0-7.
When the client sends a command to the node, if it happens to find that slot belongs to the current node, then the node executes the command, otherwise, it will return a MOVED command to the client to direct the client to the correct node. (the MOVED process is automatic)
If you add or remove nodes, it is also very convenient for the reallocation of slot. Redis provides tools to help migrate slot. The whole process is completely online and there is no need to stop the service.
Fail-over
If node A sends a ping message to node B and node B does not respond to pong within the specified time, then node A will mark node B as suspected pfail offline and send B's status to other nodes in the form of a message. If more than half of the nodes are marked as pfail, B will be marked as fail offline, and a failover will occur. Priority is given to selecting a slave node from a slave node with more replicated data as the master node and taking over the slot of the offline node. The whole process is very similar to the Sentinel, which makes the election based on the Raft protocol.
The above is all the contents of the article "sample Analysis of redis Cluster principles". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.