summaryrefslogtreecommitdiff
path: root/src/db.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-02-25 11:15:03 +0100
committerantirez <antirez@gmail.com>2013-02-25 11:15:03 +0100
commit1abce14611e01b38e0b461a12a01ce71b35a6342 (patch)
treecdf76557ccdd212bfea1b3f28b9826b03b9951e1 /src/db.c
parent825e07f2fd8949cffabcc0d5800ea46778dddafd (diff)
downloadredis-1abce14611e01b38e0b461a12a01ce71b35a6342.tar.gz
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.
Diffstat (limited to 'src/db.c')
-rw-r--r--src/db.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/db.c b/src/db.c
index 7ecb959c1..d4d24b7ae 100644
--- a/src/db.c
+++ b/src/db.c
@@ -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;
+}