# CLUSTER GETKEYSINSLOT

> List up to a given number of the keys the receiving node holds in a hash slot.

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

```
CLUSTER GETKEYSINSLOT slot count
```

- 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 GETKEYSINSLOT` returns up to `count` key names that the receiving
node holds in the given hash slot. Resharding tools call it in a loop on the
source node: fetch a batch of keys, move them with
[MIGRATE](https://docs.hotkv.com/commands/migrate/index.md), and repeat until the reply is empty.

Keys whose time to live has run out are left out. The keys are those of the
selected database: a cluster node has one database unless `cluster-databases`
is above 1, and then the command lists the keys of the database the connection
has selected. With cluster mode off the reply is always an empty array.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Valid arguments | Array of bulk strings (empty when the slot has no keys or `count` is 0) | Array |
| `slot` or `count` not an integer | Error `ERR value is not an integer or out of range` | Same error |
| Slot not from 0 to 16383, or a negative `count` | Error `ERR Invalid slot or number of keys` | Same error |

The order of the keys is not defined.

## Examples

```
127.0.0.1:6379> CLUSTER GETKEYSINSLOT 1649 10
1) "user:1000"
2) "{user:1000}:cart"
3) "{user:1000}:sessions"
127.0.0.1:6379> CLUSTER GETKEYSINSLOT 1649 -1
(error) ERR Invalid slot or number of keys
```

## Compatibility

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

## See also

[CLUSTER COUNTKEYSINSLOT](https://docs.hotkv.com/commands/cluster-countkeysinslot/index.md),
[MIGRATE](https://docs.hotkv.com/commands/migrate/index.md), [CLUSTER SETSLOT](https://docs.hotkv.com/commands/cluster-setslot/index.md)

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