aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/redis_scripts/bayes_stat.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-12-08 16:51:04 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-12-08 16:51:04 +0000
commitb11f8216f0db7a79b13b83b39e6a6ab1e7bad108 (patch)
tree71f8aad69fd7effe2cf31487a0ab2856653ef8cd /lualib/redis_scripts/bayes_stat.lua
parentcd568d70852da3d948783060d70bb3de531266e2 (diff)
downloadrspamd-b11f8216f0db7a79b13b83b39e6a6ab1e7bad108.tar.gz
rspamd-b11f8216f0db7a79b13b83b39e6a6ab1e7bad108.zip
[Project] Add some stats
Diffstat (limited to 'lualib/redis_scripts/bayes_stat.lua')
-rw-r--r--lualib/redis_scripts/bayes_stat.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/lualib/redis_scripts/bayes_stat.lua b/lualib/redis_scripts/bayes_stat.lua
index e69de29bb..31e51280c 100644
--- a/lualib/redis_scripts/bayes_stat.lua
+++ 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