SFLUSH
SFLUSH start-slot end-slot [start-slot end-slot ...] [SYNC | ASYNC]
- Group
- Cluster
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- write
- 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: 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
Section titled “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
Section titled “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
Section titled “Examples”On the primary of slots 0 to 5460, which holds four keys:
127.0.0.1:7000> DBSIZE(integer) 4127.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 3127.0.0.1:7000> SFLUSH 0 20000(error) ERR Invalid or out of range slot127.0.0.1:7000> SFLUSH 1 5 3 7(error) ERR Slot 3 specified multiple times127.0.0.1:7000> SFLUSH 1(error) ERR wrong number of arguments for 'sflush' command127.0.0.1:7000> SFLUSH 10 20 30 40 ASYNC1) 1) (integer) 10 2) (integer) 202) 1) (integer) 30 2) (integer) 40127.0.0.1:7000> SFLUSH 0 16383 SYNC1) 1) (integer) 0 2) (integer) 5460127.0.0.1:7000> DBSIZE(integer) 0The 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> READONLYOK127.0.0.1:7003> GET user:1000"ada"127.0.0.1:7000> SFLUSH 0 54601) 1) (integer) 0 2) (integer) 5460127.0.0.1:7003> GET user:1000(nil)Compatibility
Section titled “Compatibility”The command and its errors follow Redis 8’s SFLUSH, which Redis marks
experimental.
See also
Section titled “See also”CLUSTER FLUSHSLOT, CLUSTER SLOTS, FLUSHALL, FLUSHDB
In a cluster: Scaling a cluster
Was this page helpful?
Thanks for the feedback.