aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-08-31 23:25:02 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-08-31 23:32:42 +0100
commit02db3e291d9b1301faa052af992ee923e2d266e3 (patch)
treecdaca46467a999f8558e8c60c142716fa255776f
parentc47f428ed5c78a39bdcfa017db589352474b477d (diff)
downloadrspamd-02db3e291d9b1301faa052af992ee923e2d266e3.tar.gz
rspamd-02db3e291d9b1301faa052af992ee923e2d266e3.zip
[Fix] Fix synchronous auth/select in lua_redis
Issue: #4255
-rw-r--r--lualib/lua_redis.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua
index fa7d52992..a34adff6b 100644
--- a/lualib/lua_redis.lua
+++ b/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