瀏覽代碼

[Fix] Fix synchronous auth/select in lua_redis

Issue: #4255
tags/3.3
Vsevolod Stakhov 1 年之前
父節點
當前提交
02db3e291d
No account linked to committer's email address
共有 1 個文件被更改,包括 16 次插入1 次删除
  1. 16
    1
      lualib/lua_redis.lua

+ 16
- 1
lualib/lua_redis.lua 查看文件

@@ -1422,21 +1422,36 @@ local function redis_connect_sync(redis_params, is_write, key, cfg, ev_base)

local ret,conn = rspamd_redis.connect_sync(options)
if not ret then
logger.errx('cannot execute redis request: %s', conn)
logger.errx('cannot create redis connection: %s', conn)
addr:fail()

return false,nil,addr
end

if conn then
local need_exec = false
if redis_params['password'] then
conn:add_cmd('AUTH', {redis_params['password']})
need_exec = true
end

if redis_params['db'] then
conn:add_cmd('SELECT', {tostring(redis_params['db'])})
need_exec = true
elseif redis_params['dbname'] then
conn:add_cmd('SELECT', {tostring(redis_params['dbname'])})
need_exec = true
end

if need_exec then
local exec_ret, res = conn:exec()

if not exec_ret then
logger.errx('cannot prepare redis connection (authentication or db selection failure): %s',
res)
addr:fail()
return false,nil,addr
end
end
end


Loading…
取消
儲存