How to delete keys matching a certain pattern in redis using redis-cli. I would like to delete all foo's from the following list.
KEYS *
foo:1
foo:2
bar:1
foo:3
bar:2
foo:4
I wanted to delete thousands of keys by pattern after some searches I found these points:
-n [number]
del
but if there are thousands or millions of keys it's better to use unlink
because unlink is non-blocking while del is blocking, for more information visit this page unlink vs del
keys
are like del and is blockingso I used this code to delete keys by pattern:
redis-cli -n 2 --scan --pattern '[your pattern]' | xargs redis-cli -n 2 unlink
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With