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 KEYSLOT

Last updated
CLUSTER KEYSLOT key
Group
Cluster
Complexity
O(N) where N is the length of the key
Arity
3 (exactly, counting the command name)
HotKV Cloud
All plans
On-Premise
no license needed

CLUSTER KEYSLOT returns the hash slot (0 to 16383) of a key name, computed with the standard CRC16 cluster hash. If the key contains a hash tag, a non-empty part between the first { and the next }, only that part is hashed, so user:1000 and {user:1000}:cart share a slot.

The key does not need to exist. The command works with cluster mode off too, which is handy for checking how keys would be distributed.

Integer in RESP2 and RESP3: the slot.

127.0.0.1:6379> CLUSTER KEYSLOT order:77
(integer) 9221
127.0.0.1:6379> CLUSTER KEYSLOT {user:1000}:cart
(integer) 1649
127.0.0.1:6379> CLUSTER KEYSLOT user:1000
(integer) 1649

Same slot function and replies as Redis 7 and Valkey 8, so a client that computes slots itself agrees with HotKV.

CLUSTER COUNTKEYSINSLOT, CLUSTER SLOTS, Clustering: Slots and redirects