# CLUSTER COUNTKEYSINSLOT

> Count the keys the receiving node holds in a hash slot.

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

```
CLUSTER COUNTKEYSINSLOT slot
```

- Group: Cluster
- Complexity: O(N) where N is the number of keys in the slot
- HotKV Cloud: all plans
- On-Premise: no license needed

`CLUSTER COUNTKEYSINSLOT` returns how many keys the receiving node holds in
the given hash slot. Only this node's own keys count, so ask the node that
serves the slot. During a reshard you can use it on the source node to see
when a slot is empty and ready for
[CLUSTER SETSLOT NODE](https://docs.hotkv.com/commands/cluster-setslot/index.md).

Keys whose time to live has run out are not counted. The count is for the
selected database: a cluster node has one database unless `cluster-databases`
is above 1, and then `CLUSTER COUNTKEYSINSLOT` counts in the database the
connection has selected. With cluster mode off the reply is always 0.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Valid slot | Integer: the number of keys | Integer |
| Not an integer | Error `ERR value is not an integer or out of range` | Same error |
| Not from 0 to 16383 | Error `ERR Invalid slot` | Same error |

## Examples

```
127.0.0.1:6379> CLUSTER KEYSLOT user:1000
(integer) 1649
127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 1649
(integer) 3
127.0.0.1:6379> CLUSTER COUNTKEYSINSLOT 20000
(error) ERR Invalid slot
```

## Compatibility

Same replies and error strings as Redis 7 and Valkey 8.

## See also

[CLUSTER GETKEYSINSLOT](https://docs.hotkv.com/commands/cluster-getkeysinslot/index.md),
[CLUSTER KEYSLOT](https://docs.hotkv.com/commands/cluster-keyslot/index.md),
[CLUSTER SLOT-STATS](https://docs.hotkv.com/commands/cluster-slot-stats/index.md)

In a cluster: [Scaling a cluster](https://docs.hotkv.com/clustering/scaling/index.md#resharding-by-hand)