There is no straightforward method, so write a script
To delete Redis data with a pattern, click Delete keys that match the Redis pattern. Although it is introduced in articles (although it is not a straightforward method), when using Redis Cluster, data even if the prefix of the key is the same Is distributed across the nodes, making it difficult to browse and delete at once.
In the first place, I rarely do that in the release environment, but I'm a little troubled when using Redis Cluster from the development environment. What to do if you accidentally save corrupted data and finally want to delete it.
From the results, writing a script like this is the fastest.
delete-pat
#! /usr/bin/env python
import sys
import commands
print sys.argv
#Please set the node yourself.
nodes = [
"localhost:10000",
"localhost:10001",
"localhost:10002"
]
pat = sys.argv[1]
for node in nodes:
host, port = node.split(":")
output = commands.getoutput("redis-cli -h {host} -p {port} -c keys {pat}".format(host=host,port=port,pat=pat))
result = filter(lambda s:len(s) > 0, output.split("\n"))
print host, port
print result
for key in result:
print commands.getoutput("redis-cli -h {host} -p {port} -c del {key}".format(host=host,port=port,key=key))
I use it like this
./delete-pat hoge:fuga:*
That's all from here.
Recommended Posts