Cluster: added new API countKeysInSlot().

This is similar to getKeysInSlot() but just returns the number of keys
found in a given hash slot, without returning the keys.
This commit is contained in:
antirez 2013-02-25 11:15:03 +01:00
parent 825e07f2fd
commit 1abce14611

View File

@ -778,3 +778,19 @@ unsigned int GetKeysInSlot(unsigned int hashslot, robj **keys, unsigned int coun
}
return j;
}
unsigned int CountKeysInSlot(unsigned int hashslot) {
zskiplistNode *n;
zrangespec range;
int j = 0;
range.min = range.max = hashslot;
range.minex = range.maxex = 0;
n = zslFirstInRange(server.cluster->slots_to_keys, range);
while(n && n->score == hashslot) {
j++;
n = n->level[0].forward;
}
return j;
}