Purge Redis Keys with Lua Script

Redis has some powerful Lua scripting capabilities. One of the uses I’ve found for this feature is purging cache keys. On occasion I need to purge a set of keys that all have the same prefix.

The following command will do just that.

EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 prefix:*

Replace prefix with whatever prefix you are looking for and they will be deleted from Redis.