From 17ac00078d6d7c0377c270a3f663e91584fcab9c Mon Sep 17 00:00:00 2001 From: subnetmarco <88.marco@gmail.com> Date: Sat, 14 Sep 2024 11:39:35 -0400 Subject: [PATCH] all databases --- spec/helpers/redis_helper.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/helpers/redis_helper.lua b/spec/helpers/redis_helper.lua index 78c00a0a880e..91f33903f08e 100644 --- a/spec/helpers/redis_helper.lua +++ b/spec/helpers/redis_helper.lua @@ -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