Reputation: 304
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?
Upvotes: 1
Views: 786
Reputation: 6774
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:
07c3...b91 127...1:30004@31004 slave e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca 0 1426238317239 4 connected
67ed...fa1 127...1:30002@31002 master - 0 1426238316232 2 connected 5461-10922
292f...f4f 127...1:30003@31003 master - 0 1426238318243 3 connected 10923-16383
6ec2...e01 127...1:30005@31005 slave 67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 0 1426238316232 5 connected
824f...ac3 127...1:30006@31006 slave 292f8b365bb7edb5e285caf0b7e6ddc7265d2f4f 0 1426238317741 6 connected
e7d1...9ca 127...1:30001@31001 myself,master - 0 0 1 connected 0-5460
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.
Upvotes: 0
Reputation: 50112
The redis-cli can do something like this with the following syntax:
redis-cli --cluster call 1.2.3.4:9876 flushall
Where the ip:port is one of your cluster's nodes. This will run the command on all nodes.
Upvotes: 1