Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SFLUSH

Last updated
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.

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.

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.

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)

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

CLUSTER FLUSHSLOT, CLUSTER SLOTS, FLUSHALL, FLUSHDB

In a cluster: Scaling a cluster