From 4dfe49bc169346ae120bafbda643f0477886da41 Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Mon, 1 Oct 2018 10:41:51 +0100 Subject: [PATCH] [Minor] Fixed sync redis connection with default arguments in rspamadm --- lualib/lua_redis.lua | 26 +++++++++++++------ .../lua/rspamadm/test_redis_client.lua | 6 ++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua index 92ff4cc12..e95981c82 100644 --- a/lualib/lua_redis.lua +++ b/lualib/lua_redis.lua @@ -997,12 +997,6 @@ local function redis_connect_sync(redis_params, is_write, key, cfg, ev_base) if not redis_params then return false,nil end - if not cfg then - cfg = rspamd_config - end - if not ev_base then - ev_base = rspamadm_ev_base - end local rspamd_redis = require "rspamd_redis" local addr @@ -1028,14 +1022,30 @@ local function redis_connect_sync(redis_params, is_write, key, cfg, ev_base) local options = { host = addr:get_addr(), timeout = redis_params['timeout'], - config = cfg, - ev_base = ev_base + config = cfg or rspamd_config, + ev_base = ev_base or rspamadm_ev_base, + session = redis_params.session or rspamadm_session } for k,v in pairs(redis_params) do options[k] = v end + if not options.config then + logger.errx('config is not set') + return false,nil,addr + end + + if not options.ev_base then + logger.errx('ev_base is not set') + return false,nil,addr + end + + if not options.session then + logger.errx('session is not set') + return false,nil,addr + end + local ret,conn = rspamd_redis.connect_sync(options) if not ret then logger.errx('cannot execute redis request: %s', conn) diff --git a/test/functional/lua/rspamadm/test_redis_client.lua b/test/functional/lua/rspamadm/test_redis_client.lua index 7de82cd96..a7428a807 100644 --- a/test/functional/lua/rspamadm/test_redis_client.lua +++ b/test/functional/lua/rspamadm/test_redis_client.lua @@ -8,9 +8,9 @@ local upstreams_read = upstream_list.create('127.0.0.1', 56379) local is_ok, connection = redis.redis_connect_sync({ write_servers = upstreams_write, read_servers = upstreams_read, - config = rspamd_config, - ev_base = rspamadm_ev_base, - session = rspamadm_session, +-- config = rspamd_config, +-- ev_base = rspamadm_ev_base, +-- session = rspamadm_session, timeout = 2 }) -- 2.39.5