You can use the following command to scan for all keys across nodes in your Redis cluster:
redis-cli -h localhost CLUSTER NODES \
| grep master \
| awk '{print $2}' \
| cut -f1 -d '@' \
| xargs -I '{}' redis-cli -u redis://{} --scan --pattern '*'
TL;DR: Get all the IP and port of all nodes in the cluster and scan for keys on each of them.
redis-cli -h localhost CLUSTER NODES
obtains all information from the cluster configuration, including the node addresses to connect to for running commands
grep master
selects only the master nodes
awk '{print $2}'
selects the second column containg IP, port and cluster bus port
cut -f1 -d '@'
to truncate the cluster bus port
xargs
in combination with redis-cli
to run the desired command. The -u
flag makes it possible to provide server address and port in one string
Similarily you can also execute node-specific commands on every cluster nodes, see here.
Also, in the above command, make sure to replace localhost
with your actual host address, provide a port with -p
if necessary.
Keep in mind, while the cost of scanning keys is less than KEYS *
, it can still impact performance.