redis-cli
provides a -c
option to follow MOVED
redirects. However, it should be deleted one at a time because you cannot guarantee two keys will be in the same node.
redis-cli -h myredis.internal --scan --pattern 'mycachekey::*' | \ xargs -L 1 -d'\n' redis-cli -h myredis.internal -c del
The first part provides a list of keys --scan
prevents Redis from locking. xargs -L 1
runs the command for one entry at a time. -d'\n'
disables the processing of quotes so you can have quoted strings like "SimpleKey[hello world]"
be passed to the command otherwise the spaces will make it have two keys.