Get the App
SLTechnology News&Howtos  ›  Database  › 

Example Analysis of Cluster in Redis

Shulou Source: shulou.com Published: 2022-05-31 19:47:05 09月23日 Update

Xiaobian to share with you the example analysis of Cluster in Redis, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

1.1 Introduction to Redis-Cluster

1.1.1 What is Redis-Cluster?

Why build a Redis cluster? Redis stores data in memory, and our computers generally have small memory, which means that Redis is not suitable for storing big data. Hbase or MogoDB of Hadoop ecosystem is suitable for storing big data. Redis is more suitable for dealing with high concurrency, the storage capacity of a device is very limited, but multiple devices can cooperate to increase the memory many times, which requires the use of clusters.

There are many ways to build Redis clusters, such as using client-side shards, Twemproxy, Codis, etc., but redis-cluster clusters are supported in versions after Redis 3.0, which is the official solution proposed by Redis. Redis-Cluster adopts a decentralized structure, each node stores data and the entire cluster state, and each node is connected to all other nodes. Its redis-cluster architecture is as follows:

The client is directly connected to the redis node and does not require an intermediate proxy layer. The client does not need to connect to all nodes of the cluster. Just connect to any available node in the cluster.

All redis nodes are interconnected with each other (PING-PONG mechanism), internally using binary protocol to optimize transmission speed and bandwidth.

1.1.2 Distributed Storage Mechanism-Slots

(1) redis-cluster maps all physical nodes to [0-16383]slot,cluster is responsible for maintaining nodeslotvalue

(2) There are 16384 hash slots built into the Redis cluster. When a key-value needs to be placed in the Redis cluster, redis first calculates a result using the crc16 algorithm for the key, and then calculates the remainder of the result for 16384. In this way, each key will correspond to a hash slot numbered between 0 and 16383. redis will map the hash slot to different nodes according to the number of nodes.

For example, three nodes: The values of the slot distribution are as follows:

SERVER1: 0-5460

SERVER2: 5461-10922

SERVER3: 10923-16383

1.1.2 Distributed Storage Mechanism-Slots

(1) redis-cluster maps all physical nodes to [0-16383]slot,cluster is responsible for maintaining nodeslotvalue

(2) There are 16384 hash slots built into the Redis cluster. When a key-value needs to be placed in the Redis cluster, redis first calculates a result using the crc16 algorithm for the key, and then calculates the remainder of the result for 16384. In this way, each key will correspond to a hash slot numbered between 0 and 16383. redis will map the hash slot to different nodes according to the number of nodes.

For example, three nodes: The values of the slot distribution are as follows:

SERVER1: 0-5460

SERVER2: 5461-10922

SERVER3: 10923-16383

The above is all the content of this article "Sample Analysis of Cluster in Redis", thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Nodes clusters hashes storage data results memory clients clients mechanisms articles examples analysis different three middle middle remainder content quantity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS MySQL Huawei Xiaomi