From: Vsevolod Stakhov Date: Fri, 12 Jan 2024 14:53:06 +0000 (+0000) Subject: [Minor] Rework redis servers config parsing X-Git-Tag: 3.8.0~8^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=48bfe901865d2cab00c2d92372eb16476bd08262;p=rspamd.git [Minor] Rework redis servers config parsing --- diff --git a/lualib/lua_bayes_redis.lua b/lualib/lua_bayes_redis.lua index 5ad5c3514..6f6da339e 100644 --- a/lualib/lua_bayes_redis.lua +++ b/lualib/lua_bayes_redis.lua @@ -66,12 +66,7 @@ local function gen_learn_functor(redis_params, learn_script_id) end end ---- ---- Init bayes classifier ---- @param classifier_ucl ucl of the classifier config ---- @param statfile_ucl ucl of the statfile config ---- @return a pair of (classify_functor, learn_functor) or `nil` in case of error -exports.lua_bayes_init_statfile = function(classifier_ucl, statfile_ucl, symbol, is_spam, ev_base, stat_periodic_cb) +local function load_redis_params(classifier_ucl, statfile_ucl) local redis_params -- Try load from statfile options @@ -108,6 +103,22 @@ exports.lua_bayes_init_statfile = function(classifier_ucl, statfile_ucl, symbol, return nil end + return redis_params +end + +--- +--- Init bayes classifier +--- @param classifier_ucl ucl of the classifier config +--- @param statfile_ucl ucl of the statfile config +--- @return a pair of (classify_functor, learn_functor) or `nil` in case of error +exports.lua_bayes_init_statfile = function(classifier_ucl, statfile_ucl, symbol, is_spam, ev_base, stat_periodic_cb) + + local redis_params = load_redis_params(classifier_ucl, statfile_ucl) + + if not redis_params then + return nil + end + local classify_script_id = lua_redis.load_redis_script_from_file("bayes_classify.lua", redis_params) local learn_script_id = lua_redis.load_redis_script_from_file("bayes_learn.lua", redis_params) local stat_script_id = lua_redis.load_redis_script_from_file("bayes_stat.lua", redis_params) @@ -161,4 +172,12 @@ exports.lua_bayes_init_statfile = function(classifier_ucl, statfile_ucl, symbol, return gen_classify_functor(redis_params, classify_script_id), gen_learn_functor(redis_params, learn_script_id) end +exports.lua_bayes_init_cache = function(classifier_ucl, statfile_ucl) + local redis_params = load_redis_params(classifier_ucl, statfile_ucl) + + if not redis_params then + return nil + end +end + return exports