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). */
| 747 | * { and } is hashed. This may be useful in the future to force certain |
| 748 | * keys to be in the same node (assuming no resharding is in progress). */ |
| 749 | unsigned int keyHashSlot(char *key, int keylen) { |
| 750 | int s, e; /* start-end indexes of { and } */ |
| 751 | |
| 752 | for (s = 0; s < keylen; s++) |
| 753 | if (key[s] == '{') break; |
| 754 | |
| 755 | /* No '{' ? Hash the whole key. This is the base case. */ |
| 756 | if (s == keylen) return crc16(key,keylen) & 0x3FFF; |
| 757 | |
| 758 | /* '{' found? Check if we have the corresponding '}'. */ |
| 759 | for (e = s+1; e < keylen; e++) |
| 760 | if (key[e] == '}') break; |
| 761 | |
| 762 | /* No '}' or nothing between {} ? Hash the whole key. */ |
| 763 | if (e == keylen || e == s+1) return crc16(key,keylen) & 0x3FFF; |
| 764 | |
| 765 | /* If we are here there is both a { and a } on its right. Hash |
| 766 | * what is in the middle between { and }. */ |
| 767 | return crc16(key+s+1,e-s-1) & 0x3FFF; |
| 768 | } |
| 769 | |
| 770 | /* ----------------------------------------------------------------------------- |
| 771 | * CLUSTER node API |
no test coverage detected