Redis - Delete Multiple Keys by Pattern Using Lua Script
This guide provides a simple Lua script to delete multiple keys in Redis that match a specific pattern.
Usage
Run the script from within the Redis CLI.
Replace
PATTERNin the script below with the actual key substring you want to delete in bulk.
eval "for _,k in ipairs(redis.call('keys','*PATTERN*')) do redis.call('del',k) end" 0
Explanation
The
evalcommand executes the Lua script.redis.call('keys','*PATTERN*')retrieves all keys matching the specified pattern.The
forloop iterates through the list of keys and deletes each one usingredis.call('del',k).The
0at the end indicates that no additional arguments are passed to the script.
28 September 2025