Delete all keys matching prefix from Redis (Misc)

I sometimes use redis as an application level caching tier. Occassionally I want to flush the cache by deleting all entries where the key has a certain prefix

Details

  • Language: Misc

Snippet

EVAL "for i, name in ipairs(redis.call('KEYS', ARGV[1])) do redis.call('DEL', name); end" 0 prefix*

Usage Example

docker exec -it redis \
redis-cli EVAL "for i, name in ipairs(redis.call('KEYS', ARGV[1])) do redis.call('DEL', name); end" 0 gils*