Skip to main content

CLUSTER KEYSLOT

Syntax​

CLUSTER KEYSLOT key

Time complexity: O(N) where N is the number of bytes in the key

ACL categories: @slow

The CLUSTER KEYSLOT command returns the hash slot of key: the CRC16 of the key modulo 16384. If the key contains a hash tag, only the tag is hashed, so keys with the same tag map to the same slot. With the default flags, the result is the same as in Valkey.

The slot is computed from the key name only. The command does not check whether the key exists or which node owns the slot. It requires --cluster_mode=emulated or --cluster_mode=yes. Otherwise, it returns ERR Cluster is disabled. Enabled via passing --cluster_mode=emulated|yes.

Dragonfly extracts the hash tag with the same rules that it uses for lock tags. The --locktag_delimiter, --locktag_skip_n_end_delimiters and --locktag_prefix flags change these rules, even without --lock_on_hashtags, and CLUSTER KEYSLOT follows them. With --cluster_mode=yes, the node also uses this slot to decide whether it serves a key or replies with a MOVED redirection. The result can then differ from the slot that a cluster client computes. For example, with --locktag_prefix=pre, CLUSTER KEYSLOT {user1}.a returns 5959 instead of 8106, because the key does not start with pre and is hashed as a whole.

Return​

Integer reply: the hash slot of the key, from 0 to 16383.

Examples​

dragonfly> CLUSTER KEYSLOT somekey
(integer) 11058
dragonfly> CLUSTER KEYSLOT {user1}.following
(integer) 8106
dragonfly> CLUSTER KEYSLOT {user1}.followers
(integer) 8106

See also​

CLUSTER SLOTS | CLUSTER SHARDS | CLUSTER | Cluster Mode