CLUSTER-KEYSLOT(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

✨ 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:

  1. 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 KEYSLOT command, then check if the result is the same. it's a vibe check for hashing algorithms πŸ’–
  2. 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 🫢


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