Redis allows you to list keys by giving a pattern and returning all the keys that match that pattern (KEYS ts* for example, lists all keys that start with “ts”).  You can delete all the keys by using FLUSHALL and you can delete one by using DEL, but you can’t natively delete a set of keys by giving the pattern using redis-cli alone.

But with linux (or if you have the git extensions folder in your path on Windows), you can do this:

redis-cli -h REDIS_URL KEYS “ts*” | xargs redis-cli -h REDIS_URL DEL

which deletes all the keys that start with “ts” in the redis instance pointed to by REDIS_URL.

Leave a Reply

Post Navigation