In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How many hash slots are there in redis? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
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.
"the concept of hash slot is used instead of the consistent hash algorithm. Isn't it all hash? why?"
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.
"in order to dynamically add and delete nodes, will it not lose data?"
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.
"and the cluster has a total of 2 to the 14th power and 16384 hash slots, so what are the key and value stored in each hash slot?"
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.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.