Redis-Cluster-Fast
view release on metacpan or search on metacpan
deps/hiredis-cluster/hircluster.c view on Meta::CPAN
* Key space handling
* -------------------------------------------------------------------------- */
/* 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). */
static unsigned int keyHashSlot(char *key, int keylen) {
int s, e; /* start-end indexes of { and } */
for (s = 0; s < keylen; s++)
if (key[s] == '{')
break;
/* No '{' ? Hash the whole key. This is the base case. */
if (s == keylen)
return crc16(key, keylen) & 0x3FFF;
/* '{' found? Check if we have the corresponding '}'. */
( run in 0.921 second using v1.01-cache-2.11-cpan-a5abf4f5562 )