Skip to content

Commit

Permalink
all databases
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Sep 14, 2024
1 parent e69fec5 commit 17ac000
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions spec/helpers/redis_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ local function connect(host, port, password)
end

local function reset_redis(host, port, password)
local redis_client, cursor = connect(host, port, password), "0"

repeat
local result = redis_client:scan(cursor)
cursor = result[1]
local keys = result[2]
for _, key in ipairs(keys) do redis_client:del(key) end
until cursor == "0"
local redis_client = connect(host, port, password)
local num_databases = (config_res and config_res[2]) and tonumber(config_res[2]) or 1

for db = 0, num_databases - 1 do
redis_client:select(db)
local cursor = "0"
repeat
local result = redis_client:scan(cursor)
cursor = result[1]
for _, key in ipairs(result[2]) do redis_client:del(key) end
until cursor == "0"
end

redis_client:close()
end
Expand Down

0 comments on commit 17ac000

Please sign in to comment.