CLUSTER FLUSHSLOT
CLUSTER FLUSHSLOT slot [ASYNC | SYNC]
- Group
- Cluster
- Arity
- -3 (at least 3 words, counting the command name)
- 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
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
Section titled “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
Section titled “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
Section titled “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) 2127.0.0.1:7000> CLUSTER FLUSHSLOT 15891OK127.0.0.1:7000> CLUSTER COUNTKEYSINSLOT 15891(integer) 0127.0.0.1:7000> SELECT 1OK127.0.0.1:7000[1]> CLUSTER COUNTKEYSINSLOT 15891(integer) 0127.0.0.1:7000[1]> DBSIZE(integer) 0$ redis-cli --no-raw -p 7000 PSUBSCRIBE "__keyevent@*__:del"1) "psubscribe"2) "__keyevent@*__:del"3) (integer) 11) "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> READONLYOK127.0.0.1:7003> GET {t}a"1"127.0.0.1:7003> GET {t}a(nil)(The two GETs were run before and after the flush.) ASYNC and SYNC, and
the errors:
127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 ASYNCOK127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 SYNCOK127.0.0.1:7000> CLUSTER FLUSHSLOT 99999(error) ERR Invalid or out of range slot127.0.0.1:7000> CLUSTER FLUSHSLOT 15891 LATER(error) ERR syntax error127.0.0.1:7000> CLUSTER FLUSHSLOT(error) ERR wrong number of arguments for 'cluster|flushslot' command127.0.0.1:7001> CLUSTER FLUSHSLOT 15891OK127.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
Section titled “Compatibility”The command follows Valkey 9’s CLUSTER FLUSHSLOT. Redis has
SFLUSH for the same purpose.
See also
Section titled “See also”SFLUSH, CLUSTER COUNTKEYSINSLOT, CLUSTER FLUSHSLOTS, FLUSHALL
Was this page helpful?
Thanks for the feedback.