Here's a Lua script (must... honor... the... tag...) that uses DEL
to remove the sid:'s according to your definition (despite my comment re. KEYS
's use, since Lua scripts are atomic there's no need to SCAN
here and DEL
won't work anyway since SCAN
is random) and returns the names of deleted keys:
local exp=ARGV[1] * 60 * 60 * 24;
local exs={};
local keys=redis.call('keys', 'sid:*');
for _,v in next,keys,nil do
local ttl=redis.call('ttl', v);
if ttl < exp then
redis.call('del', v);
exs[#exs + 1] = v;
end
end
return exs;
Note: this script is anything by safe to use and could probably kill your production instance (not to mention it not being cluster safe) ;)