MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterManagerKeyHashSlot

Function clusterManagerKeyHashSlot

app/redis-6.2.6/src/redis-cli.c:3282–3301  ·  view source on GitHub ↗

We have 16384 hash slots. The hash slot of a given key is obtained * as the least significant 14 bits of the crc16 of the key. * * However if the key contains the {...} pattern, only the part between * { and } is hashed. This may be useful in the future to force certain * keys to be in the same node (assuming no resharding is in progress). */

Source from the content-addressed store, hash-verified

3280 * { and } is hashed. This may be useful in the future to force certain
3281 * keys to be in the same node (assuming no resharding is in progress). */
3282static unsigned int clusterManagerKeyHashSlot(char *key, int keylen) {
3283 int s, e; /* start-end indexes of { and } */
3284
3285 for (s = 0; s < keylen; s++)
3286 if (key[s] == '{') break;
3287
3288 /* No '{' ? Hash the whole key. This is the base case. */
3289 if (s == keylen) return crc16(key,keylen) & 0x3FFF;
3290
3291 /* '{' found? Check if we have the corresponding '}'. */
3292 for (e = s+1; e < keylen; e++)
3293 if (key[e] == '}') break;
3294
3295 /* No '}' or nothing between {} ? Hash the whole key. */
3296 if (e == keylen || e == s+1) return crc16(key,keylen) & 0x3FFF;
3297
3298 /* If we are here there is both a { and a } on its right. Hash
3299 * what is in the middle between { and }. */
3300 return crc16(key+s+1,e-s-1) & 0x3FFF;
3301}
3302
3303/* Return a string representation of the cluster node. */
3304static sds clusterManagerNodeInfo(clusterManagerNode *node, int indent) {

Callers 1

Calls 1

crc16Function · 0.85

Tested by

no test coverage detected