Table of contents
1. Disadvantages of consensus algorithm partitioning
You can refer to this article on consistent hash algorithm partitioning
2. Hash slot partition
There are 16384 hash slots built into the Redis cluster. Redis will map hash slots to different nodes approximately equally according to the number of server nodes
When writing a piece of data, redis first uses the crc16 algorithm to calculate a result for the key, and then calculates the remainder of the result to 16384, so that each key will correspond to a hash slot numbered between 0 and 16383, that is, mapped to a certain on the node
If you add a new server node, it will be much more convenient to move data in units of slots
3. Why does Redis have 16384 slots
Redis calculates a 16-bit value through the crc16 algorithm, which will generate 2 16 = 65536 2^{16} = 65536216=65536 values
Heartbeat data will occur between Redis nodes. If there are more slots, the heartbeat packet sent will be larger. The Redis cluster generally does not exceed 1000 nodes. Setting it to 16384 slots is completely sufficient, and it can also reduce the size of the heartbeat packet sent