-
-
Save mattweyant/2870203 to your computer and use it in GitHub Desktop.
# All credit: http://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-with-redis | |
redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL |
@peterpoliwoda you can do the following:
redis-cli -h <HOST> -p <PORT> -a <PASSWORD> --scan --pattern "patter*n" | xargs redis-cli -h <HOST> -p <PORT> -a <PASSWORD> unlink
Using unlink
is better then using del
as stated in: https://redis.io/commands/unlink
Thanks @ali
These commands are ridiculously slow when you have millions of keys
@peterpoliwoda you can do the following:
redis-cli -h <HOST> -p <PORT> -a <PASSWORD> --scan --pattern "patter*n" | xargs redis-cli -h <HOST> -p <PORT> -a <PASSWORD> unlink
Using
unlink
is better then usingdel
as stated in: https://redis.io/commands/unlink
Thanks, it did work.
If your keys have any escape characters you need to change the xargs delimiter:
redis-cli --scan --pattern "horizon:failed:*" | xargs -n 1 -d '\n' redis-cli DEL
that's my case, it worked - thanks a lot @jessecurry
How do I achieve the same using the redis pypi package ? Right now I'm using r.delete(*r.keys("someKey_*"))
How can you do this with authentication?
I need to login to my remote redis first
to get into the redis-cli and run auth with a password to get into the db:
Is it possible then to run the
KEYS patter*n
command and pipe it through to a DEL inside of redis-cli already?Something along the lines of
This above doesn't work, I'm looking for something that might.