In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how many slots there are in redis, and the code is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
There are 16384 hash slots built into the Redis cluster. When you need to place a key-value in the Redis cluster, redis first uses the crc16 algorithm to calculate a result for the key, and then calculates the remainder of the result for 16384, so that each key will correspond to a hash slot numbered between 0 and 16383, and redis will map the hash slot to different nodes according to the number of nodes. Instead of using consistent hash, Redis clusters introduce the concept of hash slots.
The Redis cluster has 16384 hash slots, and each key passes the CRC16 check and modulates 16384 to decide which slot to place. Each node of the cluster is responsible for part of the hash slot. This structure is easy to add or delete nodes, and whether you add, delete or modify a node, it will not cause the cluster to be unavailable.
The advantage of using hash slots is that nodes can be easily added or removed.
When you need to add nodes, you only need to move some of the hash slots of other nodes to the new nodes.
When you need to remove a node, you just need to move the hash slot on the removed node to another node
At this point, we don't have to stop all redis services when we add or remove nodes in the future.
In redis, the easiest way to put a key-value key-value pair is set key value, as follows:
127.0.0.1located at 192.168.39.153:7002OK192.168.39.153:7002 7000 > set key value- > Redirected to slot [12539] located at 192.168.39.153:7002OK192.168.39.153:7002 > get key "value" 192.168.39.153VR 7002 >
You can see that when we set the value of key to value, the client is redirected to another node 192.168.39.153 key 7002. This is because the slot corresponding to key is 12359, so our key-value is placed in the node corresponding to slot 12359, 192.168.39.153key 7002.
Redis Cluster is a simple hash algorithm for self-made crc16, without using consistent hash. The authors of Redis think that the effect of its crc16 (key) mod 16384 is good. Although it is not as flexible as consistent hash, it is easy to implement and easy to deal with when adding or deleting nodes.
Not losing data when adding or deleting nodes has nothing to do with the hash algorithm. Not losing data requires more than one copy of the data.
When you add a Key to a Redis Cluster, it calculates which hash slot the key should be distributed to according to crc16 (key) mod 16384. There will be a lot of key and value in a hash slot. You can understand the partition of the table, when using a single node redis, there is only one table, and all the key are placed in this table; after switching to Redis Cluster, it will automatically generate 16384 partition tables for you, and when you insert data, you will decide which partition your key should exist according to the above simple algorithm, and there are many key in each partition.
The above is how many slots there are in redis. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.