title: Redis wildcard delete script using EVAL, SCAN, and DEL returns "Write commands not allowed after non deterministic commands"
body: <p>So I'm on a quest to build a lua script that uses SCAN to find keys based on a pattern and Delete them (atomically).  I first prepared the following script</p>
  
  <pre><code>local keys = {};
  local done = false;
  local cursor = "0"
  repeat
      local result = redis.call("SCAN", cursor, "match", ARGV[1], "count", ARGV[2])
      cursor = result[1];
      keys = result[2];
      for i, key in ipairs(keys) do
          redis.call("DEL", key);
      end
      if cursor == "0" then
          done = true;
      end
  until done
  return true;
  </code></pre>
  
  <p>Which would spit back the following "Err: @user_script: 9: Write commands not allowed after non deterministic commands " So I thought about it a bit and came up with the following script:</p>
  
  <pre><code>local all_keys = {};
  local keys = {};
  local done = false;
  local cursor = "0"
  repeat
      local result = redis.call("SCAN", cursor, "match", ARGV[1], "count", ARGV[2])
      cursor = result[1];
      keys = result[2];
      for i, key in ipairs(keys) do
          all_keys[#all_keys+1] = key;
      end
      if cursor == "0" then
          done = true;
      end
  until done
  for i, key in ipairs(all_keys) do
      redis.call("DEL", key);
  end
  return true;
  </code></pre>
  
  <p>which still returns the same error (@user_script: 17: Write commands not allowed after non deterministic commands).  This has me stumped.  Is there any way to circumvent this issue?</p>
  
  <p>script was run using phpredis and the following</p>
  
  <pre><code>$args_arr = [
            0 =&gt; 'test*',   //pattern
            1 =&gt; 100,     //count for SCAN
    ];
    var_dump($redis-&gt;eval($script, $args_arr, 0));
  </code></pre>