I've been looking around for the recommended way to iterate over SCANs using Lua and was wondering if there was a "best practice" so to speak for it. The script below was the best I could find so far. Does anyone have anything to add? Is it wise to iterate using COUNT 1000000000? Wouldn't that be blocking?
local ans, has, cursor = {}, {}, "0";
repeat
local t = redis.call("SCAN", cursor, "MATCH", KEYS[1], "COUNT", 1000000000);
local list = t[2];
for i = 1, #list do
local s = list[i];
if has[s] == nil then has[s] = 1; ans[#ans + 1] = s; end;
end;
cursor = t[1];
until cursor == "0";
return #ans; --or return ans;
Taken from: https://github.com/antirez/redis/issues/3190#issuecomment-214022437