Can we run one command/script to find and flush all masters in Redis cluster?
I am trying to run FLUSHALL
on all masters in my cluster at once. Also whenever one of my master fails, slave of that failed master becomes Master. so when it changes to master, it should run FLUSHALL
command.
Are their any built-in functions to do this?
2
Answers
The redis-cli can do something like this with the following syntax:
Where the ip:port is one of your cluster’s nodes. This will run the command on all nodes.
Look at https://redis.io/commands/cluster-nodes and the related commands.
The output of
CLUSTER NODES
command is a space-separated CSV string, where each line represents a node in the cluster. The following is an example of output:Each line is composed of the following fields:
So with this command, you find all masters (and slaves), by type on the fourth field.
You would need to implement a monitor service to detect when to trigger your FLUSHALL commands.