Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Cluster in Redis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report