Skip to content

Instantly share code, notes, and snippets.

@nicksherron
Created January 11, 2025 03:16
Show Gist options
  • Save nicksherron/ba642d5b9a2144cf66ff329b74fd1cd4 to your computer and use it in GitHub Desktop.
Save nicksherron/ba642d5b9a2144cf66ff329b74fd1cd4 to your computer and use it in GitHub Desktop.
-- Desc: This script will return all keys that do not have a TTL set.
-- Usage: redis-cli --eval nottlkeys.lua
local nonttl = {}
local cursor = "0"
local done = false
while not done do
repeat
local result = redis.call("SCAN", cursor, "MATCH", "*", "COUNT", 1000)
cursor = result[1]
local scanned = result[2]
for i, key in ipairs(scanned) do
local ttl = redis.call("TTL", key)
if ttl == -1 then
table.insert(nonttl, key)
end
end
if cursor == "0" then
done = true
end
until done
end
return nonttl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment