# SFLUSH

> Delete every key in ranges of hash slots that the node serves, and reply with the ranges it flushed.

URL: https://docs.hotkv.com/commands/sflush/

```
SFLUSH start-slot end-slot [start-slot end-slot ...] [SYNC | ASYNC]
```

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

`SFLUSH` deletes all the keys that fall in one or more ranges of hash slots,
and replies with the ranges that it actually flushed: the parts of your ranges
that the node serves. It is the multi-slot form of
[CLUSTER FLUSHSLOT](https://docs.hotkv.com/commands/cluster-flushslot/index.md): use it to empty a slice of
the keyspace on the primary that serves it, for example to drop everything a
tenant held in a range of slots. Slots that the node does not serve are left
out of the reply and their keys are not touched.

Send `SFLUSH` to a primary. A replica refuses it, and receives the flush from
its primary: a key that was on the replica is gone after the primary flushed
its slot.

## Options

| Argument | Meaning |
| --- | --- |
| `start-slot end-slot` | One range of slots, both ends included, each from 0 to 16383. Give one or more pairs. |
| `SYNC` or `ASYNC` | Accepted, as in Redis. Both flushed the slots before the reply arrived. |

## Return value

An array of `[start, end]` pairs, the ranges this node served and flushed, in
the same form in RESP2 and RESP3. The array is empty when the node serves none
of the slots. Errors:

| Error | Cause |
| --- | --- |
| `ERR Invalid or out of range slot` | A slot is not a number from 0 to 16383. |
| `ERR start slot number 5 is greater than end slot number 3` | A range runs backwards (the numbers are yours). |
| `ERR Slot 3 specified multiple times` | The ranges overlap. |
| `ERR wrong number of arguments for 'sflush' command` | A slot without its partner, or no slots. |
| `READONLY You can't write against a read only replica.` | Sent to a replica. |

## Examples

On the primary of slots 0 to 5460, which holds four keys:

```
127.0.0.1:7000> DBSIZE
(integer) 4
127.0.0.1:7000> SFLUSH 6000 7000
(empty array)
127.0.0.1:7000> SFLUSH 5 3
(error) ERR start slot number 5 is greater than end slot number 3
127.0.0.1:7000> SFLUSH 0 20000
(error) ERR Invalid or out of range slot
127.0.0.1:7000> SFLUSH 1 5 3 7
(error) ERR Slot 3 specified multiple times
127.0.0.1:7000> SFLUSH 1
(error) ERR wrong number of arguments for 'sflush' command
127.0.0.1:7000> SFLUSH 10 20 30 40 ASYNC
1) 1) (integer) 10
   2) (integer) 20
2) 1) (integer) 30
   2) (integer) 40
127.0.0.1:7000> SFLUSH 0 16383 SYNC
1) 1) (integer) 0
   2) (integer) 5460
127.0.0.1:7000> DBSIZE
(integer) 0
```

The range `6000 7000` belongs to another node, so nothing was flushed and the
reply is empty. `SFLUSH 0 16383` covers the whole keyspace and flushes the
slots this node serves, 0 to 5460.

The flush reaches the replica:

```
127.0.0.1:7003> READONLY
OK
127.0.0.1:7003> GET user:1000
"ada"
127.0.0.1:7000> SFLUSH 0 5460
1) 1) (integer) 0
   2) (integer) 5460
127.0.0.1:7003> GET user:1000
(nil)
```

## Compatibility

The command and its errors follow Redis 8's `SFLUSH`, which Redis marks
experimental.

## See also

[CLUSTER FLUSHSLOT](https://docs.hotkv.com/commands/cluster-flushslot/index.md),
[CLUSTER SLOTS](https://docs.hotkv.com/commands/cluster-slots/index.md),
[FLUSHALL](https://docs.hotkv.com/commands/flushall/index.md), [FLUSHDB](https://docs.hotkv.com/commands/flushdb/index.md)

In a cluster: [Scaling a cluster](https://docs.hotkv.com/clustering/scaling/index.md#clear-a-slot-or-a-range)