CLUSTER-KEYSLOT(3valkey)
β¨ CLUSTER-KEYSLOT β¨
okay bestie, welcome to the cluster-keyslot page from the Valkey Command Manual π
this one is short and sweet and it is literally just "which hash slot does this key live in" and honestly? iconic.
π NAME π
cluster-keyslot β returns the hash slot for a key. that's it. that's the whole job. no cap.
πΈ SYNOPSIS πΈ
CLUSTER KEYSLOT key
π¦ DESCRIPTION π¦
so basically it hands you back an integer that identifies the hash slot your specified key hashes to. simple as that, fr fr.
This command is mainly useful for debugging and testing, because it exposes the underlying Valkey implementation of the hashing algorithm through an API. like, it's giving "peek behind the curtain" energy.
example use cases for this command, bestie:
- Client libraries may use Valkey in order to test their own hashing algorithm β they generate random keys and hash them with both their local implementation and using Valkey
CLUSTER KEYSLOTcommand, then check if the result is the same. it's a vibe check for hashing algorithms π - Humans may use this command in order to check what is the hash slot, and then the associated Valkey Cluster node, responsible for a given key. yes, you. you're the human. you got this π«Ά
π REPLY π
valkey-protocol(7) Integer reply: the hash slot number for the specified key β¨
π₯ COMPLEXITY π₯
O(N) where N is the number of bytes in the key. yeah it scales with the key length, that's the whole deal π
π ACL CATEGORIES π
@slow
π HISTORY π
- Available since:
3.0.0β
πΈ Example πΈ
> CLUSTER KEYSLOT somekey
(integer) 11058
> CLUSTER KEYSLOT foo{hash_tag}
(integer) 2515
> CLUSTER KEYSLOT bar{hash_tag}
(integer) 2515
Note that the command implements the full hashing algorithm, including support for valkey-cluster-spec(7) hash tags. and what even is that? okay so it's that special property of the Valkey Cluster key hashing algorithm where it hashes just what is between { and } if such a pattern is found inside the key name β and the reason is to force multiple keys to be handled by the same node π§π« (peep the example above: foo{hash_tag} and bar{hash_tag} both land on 2515, iykyk).
π«Ά SEE ALSO π«Ά
asking(3valkey),cluster(3valkey),cluster-addslots(3valkey),cluster-addslotsrange(3valkey),cluster-bumpepoch(3valkey),cluster-cancelslotmigrations(3valkey),cluster-count-failure-reports(3valkey),cluster-countkeysinslot(3valkey),cluster-delslots(3valkey),cluster-delslotsrange(3valkey),cluster-failover(3valkey),cluster-flushslots(3valkey),cluster-forget(3valkey),cluster-getkeysinslot(3valkey),cluster-getslotmigrations(3valkey),cluster-help(3valkey),cluster-info(3valkey),cluster-links(3valkey),cluster-meet(3valkey),cluster-migrateslots(3valkey),cluster-myid(3valkey),cluster-myshardid(3valkey),cluster-nodes(3valkey),cluster-replicas(3valkey),cluster-replicate(3valkey),cluster-reset(3valkey),cluster-saveconfig(3valkey),cluster-set-config-epoch(3valkey),cluster-setslot(3valkey),cluster-shards(3valkey),cluster-slot-stats(3valkey),cluster-slots(3valkey),cluster-syncslots(3valkey),readonly(3valkey),readwrite(3valkey)
okay that's the whole page bestie, you ate it π
β¨ this was Valkey 9.0.0, dated 2025-10-21 β go forth and hash responsibly, mwah ππ¦π
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms