Skip to content

Instantly share code, notes, and snippets.

@cthulhu666
Last active February 12, 2018 17:03
Show Gist options
  • Save cthulhu666/1f413d285520b56f427311fa2160ac52 to your computer and use it in GitHub Desktop.
Save cthulhu666/1f413d285520b56f427311fa2160ac52 to your computer and use it in GitHub Desktop.
-- 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
@cthulhu666
Copy link
Author

cthulhu666 commented Feb 12, 2018

Lua script for expiring Redis keys that don't have TTL set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment