diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-01-12 14:53:06 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-01-12 14:53:06 +0000 |
commit | 48bfe901865d2cab00c2d92372eb16476bd08262 (patch) | |
tree | 3a7d9c7a59a6d78d4e3de14badc0b503593795d3 /lualib | |
parent | dea397a3b10f45f0f263ca2c8fa54eeb5b2ede82 (diff) | |
download | rspamd-48bfe901865d2cab00c2d92372eb16476bd08262.tar.gz rspamd-48bfe901865d2cab00c2d92372eb16476bd08262.zip |
[Minor] Rework redis servers config parsing
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_bayes_redis.lua | 31 |
1 files changed, 25 insertions, 6 deletions
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 |