CLUSTER COUNTKEYSINSLOT
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.
Return value
Section titled “Return value”| 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 |
Examples
Section titled “Examples”127.0.0.1:6379> CLUSTER KEYSLOT user:1000(integer) 1649127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 1649(integer) 3127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 20000(error) ERR Invalid slotCompatibility
Section titled “Compatibility”Same replies and error strings as Redis 7 and Valkey 8.
See also
Section titled “See also”CLUSTER GETKEYSINSLOT, CLUSTER KEYSLOT, CLUSTER SLOT-STATS
In a cluster: Scaling a cluster
Was this page helpful?
Thanks for the feedback.