Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(helpers): supporting Redis cluster and optional Redis password #13654

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions spec/helpers/redis_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@ local version = require "version"
local DEFAULT_TIMEOUT = 2000


local function connect(host, port)
local function connect(host, port, password)
local redis_client = redis:new()
redis_client:set_timeout(DEFAULT_TIMEOUT)
assert(redis_client:connect(host, port))
if password then
assert(redis_client:auth(password))
end
local red_version = string.match(redis_client:info(), 'redis_version:([%g]+)\r\n')
return redis_client, assert(version(red_version))
end

local function reset_redis(host, port)
local redis_client = connect(host, port)
redis_client:flushall()
local function reset_redis(host, port, password)
local redis_client = connect(host, port, password)

local config_res = redis_client:config("get", "databases")
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
Loading