Delete all keys matching prefix from Redis



Published: 2023-12-23 15:13:50 +0000
Categories: Misc,

Language

Misc

Description

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

Based On

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*

Keywords

redis, cache, purge, delete, prefix,

Latest Posts


Copyright © 2023 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter github.com/bentasker