diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
commit | 133a45c109da5310add55824db21af5239951f93 (patch) | |
tree | ba6ac4c0a950a0dda56451944315d66409923918 /lualib/redis_scripts/bayes_stat.lua | |
parent | Initial commit. (diff) | |
download | rspamd-133a45c109da5310add55824db21af5239951f93.tar.xz rspamd-133a45c109da5310add55824db21af5239951f93.zip |
Adding upstream version 3.8.1.upstream/3.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lualib/redis_scripts/bayes_stat.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lualib/redis_scripts/bayes_stat.lua b/lualib/redis_scripts/bayes_stat.lua new file mode 100644 index 0000000..31e5128 --- /dev/null +++ b/lualib/redis_scripts/bayes_stat.lua @@ -0,0 +1,19 @@ +-- Lua script to perform bayes stats +-- This script accepts the following parameters: +-- key1 - current cursor +-- key2 - symbol to examine +-- key3 - learn key (e.g. learns_ham or learns_spam) +-- key4 - max users + +local cursor = tonumber(KEYS[1]) + +local ret = redis.call('SSCAN', KEYS[2] .. '_keys', cursor, 'COUNT', tonumber(KEYS[4])) + +local new_cursor = tonumber(ret[1]) +local nkeys = #ret[2] +local learns = 0 +for _, key in ipairs(ret[2]) do + learns = learns + (tonumber(redis.call('HGET', key, KEYS[3])) or 0) +end + +return { new_cursor, nkeys, learns }
\ No newline at end of file |