Last active
July 4, 2018 09:50
-
-
Save yogin16/931a354933e41c14fca9f6113497db20 to your computer and use it in GitHub Desktop.
Lua script for cleaning Spring's Redis cache (@Cacheable)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- $ ./redis-cli --eval cleanSpringRedisCache.lua <CACHE_NAME> | |
local logtable = {} | |
local function logit(msg) | |
logtable[#logtable+1] = msg | |
end | |
local cacheName=KEYS[1]..'~keys' | |
logit('Cache: '..cacheName) | |
local cacheValues=redis.call("zrevrange", cacheName, 0, 100) | |
for i, key in ipairs(cacheValues) do | |
logit('Key: '..key) | |
redis.call("zrem", cacheName, key) | |
redis.call("del", key) | |
end | |
return logtable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Enhanced further for complete pagination