Last active
February 12, 2018 17:03
-
-
Save cthulhu666/1f413d285520b56f427311fa2160ac52 to your computer and use it in GitHub Desktop.
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
-- Usage: redis-cli --eval redis_expire_keys.lua <key-pattern> , <ttl-in-seconds> | |
local keys = redis.call("keys", KEYS[1]) | |
local toExpire = {} | |
local i = 1 -- "it is customary in Lua to start arrays with index 1" | |
for _, key in ipairs(keys) do | |
local val = redis.call('ttl', key) | |
if val == -1 then | |
toExpire[i] = key | |
redis.call('expire', key, ARGV[1]) | |
i = i + 1 | |
end | |
end | |
return toExpire |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lua script for expiring Redis keys that don't have TTL set.