# CLUSTER KEYSLOT

> Return the hash slot a key maps to.

URL: https://docs.hotkv.com/commands/cluster-keyslot/

```
CLUSTER KEYSLOT key
```

- Group: Cluster
- Complexity: O(N) where N is the length of the key
- 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.

## Return value

Integer in RESP2 and RESP3: the slot.

## Examples

```
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
```

## Compatibility

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

## See also

[CLUSTER COUNTKEYSINSLOT](https://docs.hotkv.com/commands/cluster-countkeysinslot/index.md),
[CLUSTER SLOTS](https://docs.hotkv.com/commands/cluster-slots/index.md),
[Clustering: Slots and redirects](https://docs.hotkv.com/clustering/index.md#slots-and-redirects)