# CLUSTER FLUSHSLOT

> Delete every key of one hash slot, in every database, on the node that receives the command and on its replicas.

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

```
CLUSTER FLUSHSLOT slot [ASYNC | SYNC]
```

- Group: Cluster
- HotKV Cloud: not available
- On-Premise: no license needed

`CLUSTER FLUSHSLOT` deletes all the keys of one hash slot from the node it is
sent to. It is a way to empty a slot without touching the rest of the node, for
example to drop the data of one hash tag. Send it to the primary that serves
the slot: the node deletes the keys it holds for that slot, and replies `OK`
without checking whether it serves the slot, so on any other node it deletes
nothing and still replies `OK`.

The command deletes the slot's keys in every database of the node (see
`cluster-databases`), sends the deletions to the replicas, and publishes a `del` keyspace event for each key when keyspace
notifications are on. The entries of the [AI engines](https://docs.hotkv.com/clustering/ai-engines/index.md)
that belong to the slot (a cache namespace, for instance) are dropped too. A
replica refuses the command; it receives the deletions from its primary.

## Options

| Option | Effect |
| --- | --- |
| `ASYNC` | Accepted, as in Valkey. The keys were gone when the reply arrived. |
| `SYNC` | Accepted, as in Valkey. The keys were gone when the reply arrived. |

## Return value

Simple string `OK` in RESP2 and RESP3, also when the slot holds no keys.
Errors:

| Error | Cause |
| --- | --- |
| `ERR Invalid or out of range slot` | The slot is not a number from 0 to 16383. |
| `ERR syntax error` | The second option is not `ASYNC` or `SYNC`. |
| `ERR wrong number of arguments for 'cluster\|flushslot' command` | No slot given. |
| `READONLY You can't write against a read only replica.` | Sent to a replica. |

## Examples

The key `{t}` is in slot 15891. Two keys are in database 0 and one in
database 1 of a node that has `cluster-databases 2`; its replica has them too.
A subscriber on the primary listens for `del` events:

```
127.0.0.1:7000> CLUSTER COUNTKEYSINSLOT 15891
(integer) 2
127.0.0.1:7000> CLUSTER FLUSHSLOT 15891
OK
127.0.0.1:7000> CLUSTER COUNTKEYSINSLOT 15891
(integer) 0
127.0.0.1:7000> SELECT 1
OK
127.0.0.1:7000[1]> CLUSTER COUNTKEYSINSLOT 15891
(integer) 0
127.0.0.1:7000[1]> DBSIZE
(integer) 0
```

```
$ redis-cli --no-raw -p 7000 PSUBSCRIBE "__keyevent@*__:del"
1) "psubscribe"
2) "__keyevent@*__:del"
3) (integer) 1
1) "pmessage"
2) "__keyevent@*__:del"
3) "__keyevent@0__:del"
4) "{t}a"
1) "pmessage"
2) "__keyevent@*__:del"
3) "__keyevent@0__:del"
4) "{t}b"
1) "pmessage"
2) "__keyevent@*__:del"
3) "__keyevent@1__:del"
4) "{t}c"
```

The replica, which held `{t}a` before, no longer has it:

```
127.0.0.1:7003> READONLY
OK
127.0.0.1:7003> GET {t}a
"1"
127.0.0.1:7003> GET {t}a
(nil)
```

(The two `GET`s were run before and after the flush.) `ASYNC` and `SYNC`, and
the errors:

```
127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 ASYNC
OK
127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 SYNC
OK
127.0.0.1:7000> CLUSTER FLUSHSLOT 99999
(error) ERR Invalid or out of range slot
127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 LATER
(error) ERR syntax error
127.0.0.1:7000> CLUSTER FLUSHSLOT
(error) ERR wrong number of arguments for 'cluster|flushslot' command
127.0.0.1:7001> CLUSTER FLUSHSLOT 15891
OK
127.0.0.1:7003> CLUSTER FLUSHSLOT 15891
(error) READONLY You can't write against a read only replica.
```

The last two commands went to a node that does not serve slot 15891 (port
7001, nothing deleted) and to a replica.

## Compatibility

The command follows Valkey 9's `CLUSTER FLUSHSLOT`. Redis has
[SFLUSH](https://docs.hotkv.com/commands/sflush/index.md) for the same purpose.

## See also

[SFLUSH](https://docs.hotkv.com/commands/sflush/index.md),
[CLUSTER COUNTKEYSINSLOT](https://docs.hotkv.com/commands/cluster-countkeysinslot/index.md),
[CLUSTER FLUSHSLOTS](https://docs.hotkv.com/commands/cluster-flushslots/index.md),
[FLUSHALL](https://docs.hotkv.com/commands/flushall/index.md)