Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

CLUSTER COUNTKEYSINSLOT

Last updated
CLUSTER COUNTKEYSINSLOT slot
Group
Cluster
Complexity
O(N) where N is the number of keys in the slot
Arity
3 (exactly, counting the command name)
HotKV Cloud
All plans
On-Premise
no license needed

CLUSTER COUNTKEYSINSLOT returns how many keys the receiving node holds in the given hash slot. Only this node’s own keys count, so ask the node that serves the slot. During a reshard you can use it on the source node to see when a slot is empty and ready for CLUSTER SETSLOT NODE.

Keys whose time to live has run out are not counted. The count is for the selected database: a cluster node has one database unless cluster-databases is above 1, and then CLUSTER COUNTKEYSINSLOT counts in the database the connection has selected. With cluster mode off the reply is always 0.

Case RESP2 RESP3
Valid slot Integer: the number of keys Integer
Not an integer Error ERR value is not an integer or out of range Same error
Not from 0 to 16383 Error ERR Invalid slot Same error
127.0.0.1:6379> CLUSTER KEYSLOT user:1000
(integer) 1649
127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 1649
(integer) 3
127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 20000
(error) ERR Invalid slot

Same replies and error strings as Redis 7 and Valkey 8.

CLUSTER GETKEYSINSLOT, CLUSTER KEYSLOT, CLUSTER SLOT-STATS

In a cluster: Scaling a cluster