From 3f44f3664c9397e6c452446b66d029d8356c8597 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 11 Jan 2018 19:30:14 +0000 Subject: [PATCH] [Minor] Remove redundant methods --- src/plugins/lua/dynamic_conf.lua | 57 ++++-------------------------- src/plugins/lua/url_reputation.lua | 55 ++-------------------------- 2 files changed, 9 insertions(+), 103 deletions(-) diff --git a/src/plugins/lua/dynamic_conf.lua b/src/plugins/lua/dynamic_conf.lua index 0ddad354c..e83e9e256 100644 --- a/src/plugins/lua/dynamic_conf.lua +++ b/src/plugins/lua/dynamic_conf.lua @@ -19,6 +19,7 @@ local redis_params local ucl = require "ucl" local fun = require "fun" local lua_util = require "lua_util" +local rspamd_redis = require "lua_redis" local N = "dynamic_conf" if confighelp then @@ -49,54 +50,6 @@ local function alpha_cmp(v1, v2) return false end -local function redis_make_request(ev_base, cfg, key, is_write, callback, command, args) - if not ev_base or not redis_params or not callback or not command then - return false,nil,nil - end - - local addr - local rspamd_redis = require "rspamd_redis" - - if key then - if is_write then - addr = redis_params['write_servers']:get_upstream_by_hash(key) - else - addr = redis_params['read_servers']:get_upstream_by_hash(key) - end - else - if is_write then - addr = redis_params['write_servers']:get_upstream_master_slave(key) - else - addr = redis_params['read_servers']:get_upstream_round_robin(key) - end - end - - if not addr then - rspamd_logger.errx(cfg, 'cannot select server to make redis request') - end - - local options = { - ev_base = ev_base, - config = cfg, - callback = callback, - host = addr:get_addr(), - timeout = redis_params['timeout'], - cmd = command, - args = args - } - - if redis_params['password'] then - options['password'] = redis_params['password'] - end - - if redis_params['db'] then - options['dbname'] = redis_params['db'] - end - - local ret,conn = rspamd_redis.make_request(options) - return ret,conn,addr -end - local function apply_dynamic_actions(_, acts) fun.each(function(k, v) if type(v) == 'table' then @@ -186,8 +139,12 @@ local function update_dynamic_conf(cfg, ev_base, recv) if err then rspamd_logger.errx(cfg, "cannot save dynamic conf to redis: %s", err) else - redis_make_request(ev_base, cfg, settings.redis_key, true, - redis_version_set_cb, 'HINCRBY', {settings.redis_key, 'v', '1'}) + rspamd_redis.redis_make_request_taskless(ev_base, + cfg, + settings.redis_key, + true, + redis_version_set_cb, + 'HINCRBY', {settings.redis_key, 'v', '1'}) end end diff --git a/src/plugins/lua/url_reputation.lua b/src/plugins/lua/url_reputation.lua index 9dbb40320..55f568e56 100644 --- a/src/plugins/lua/url_reputation.lua +++ b/src/plugins/lua/url_reputation.lua @@ -64,58 +64,7 @@ local scale = { local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" local lua_util = require "lua_util" - --- This function is used for taskless redis requests (to load scripts) -local function redis_make_request(ev_base, cfg, key, is_write, callback, command, args) - if not ev_base or not redis_params or not callback or not command then - return false,nil,nil - end - - local addr - local rspamd_redis = require "rspamd_redis" - - if key then - if is_write then - addr = redis_params['write_servers']:get_upstream_by_hash(key) - else - addr = redis_params['read_servers']:get_upstream_by_hash(key) - end - else - if is_write then - addr = redis_params['write_servers']:get_upstream_master_slave(key) - else - addr = redis_params['read_servers']:get_upstream_round_robin(key) - end - end - - if not addr then - rspamd_logger.errx(cfg, 'cannot select server to make redis request') - end - - local options = { - ev_base = ev_base, - config = cfg, - callback = callback, - host = addr:get_addr(), - timeout = redis_params['timeout'], - cmd = command, - args = args - } - - if redis_params['password'] then - options['password'] = redis_params['password'] - end - - if redis_params['db'] then - options['dbname'] = redis_params['db'] - end - - local ret,conn = rspamd_redis.make_request(options) - if not ret then - rspamd_logger.errx('cannot execute redis request') - end - return ret,conn,addr -end +local rspamd_redis = require "lua_redis" local redis_incr_script = [[ for _, k in ipairs(KEYS) do @@ -132,7 +81,7 @@ local function load_scripts(cfg, ev_base) redis_incr_script_sha = tostring(data) end end - redis_make_request(ev_base, + rspamd_redis.redis_make_request_taskless(ev_base, rspamd_config, nil, true, -- is write -- 2.39.5