title: What's the recommended way to iterate SCANs in Lua for Redis?
body: <p>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?</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Taken from: <a href="https://github.com/antirez/redis/issues/3190#issuecomment-214022437" rel="nofollow noreferrer">https://github.com/antirez/redis/issues/3190#issuecomment-214022437</a></p>