2

From the documentation this seems how flushall would work but in practice it is not working that way. When I use the command flushall it only flushes the keys from the db instance the cli is assigned to.

Redis flushall documentation

Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.

The time-complexity for this operation is O(N), N being the number of keys in all existing databases.

For example if my cluster redis-cli has started and I search for a key and the node cli changes from 7000 to 7002 corresponding with the key that the hash is located i.e. server 7002 and then do a flush all it will delete the key per that server.

However, the other keys remain.

Is there a way to flushall meaning delete all keys across all masters and slaves?

Community
  • 1
  • 1
Christian Matthew
  • 4,014
  • 4
  • 33
  • 43

1 Answers1

15

Yes. You can use the cli's --cluster switch with the call command - it will execute the provided command on each of the cluster's master nodes (and will replicate, as FLUSHALL is a write command, to their respective slaves).

This should do it:

$ redis-cli --cluster call --cluster-only-masters <one-of-the-nodes-address>:<its-port> FLUSHALL
mickeymoon
  • 4,820
  • 5
  • 31
  • 56
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • 1
    It is in the help provided by `redis-cli --cluster help`, but not properly documented on the redis.io website (we're accepting PRs ;)) – Itamar Haber Dec 28 '19 at 14:32
  • 1
    one thing that is always a little confusing @itamar is knowing when something is a cli tool and an actual command that can be used live while the cli is active. I'd love to help with documentation as I enjoy using your product – Christian Matthew Dec 28 '19 at 15:35
  • I just tried this and it happens to execute it on ALL nodes, not only master nodes. replicas too. It requires "--cluster-only-masters" at the end after command. – sgohl Mar 01 '22 at 20:57
  • @sgohl thanks - updated my answer accordingly. – Itamar Haber Mar 03 '22 at 16:09
  • 6
    I had to put `call` before the `--cluster-only-master` flag: `redis-cli --cluster call --cluster-only-masters : FLUSHALL` – Marnix.hoh Apr 10 '22 at 15:00
  • 2
    i think the order of arguments is not optimal. it should be: redis-cli --cluster-only-masters --cluster call ... else, the current docker.io/redis returns "Unknown --cluster subcommand" – sgohl Jul 07 '22 at 11:14