til icon indicating copy to clipboard operation
til copied to clipboard

DEL many keys in Redis

Open xluffy opened this issue 2 years ago • 0 comments

local counter = 0;
local cursor = 0;

repeat
  local res, _ = redis.call("SCAN", cursor, "MATCH", "pattern-*", "COUNT", 100);
  local keys = res[2];
  for i = 1, #keys do
    local key = keys[i];
    -- redis.call("DEL", key);
    counter = counter + 1;
  end;
  cursor = res[1];
until tonumber(cursor) == 0
return "Total "..counter.." keys deleted";

xluffy avatar Dec 07 '22 09:12 xluffy