| 1 |
-- Lua script to perform bayes stats |
| 2 |
-- This script accepts the following parameters: |
| 3 |
-- key1 - current cursor |
| 4 |
-- key2 - symbol to examine |
| 5 |
-- key3 - learn key (e.g. learns_ham or learns_spam) |
| 6 |
-- key4 - max users |
| 7 |
|
| 8 |
local cursor = tonumber(KEYS[1]) |
| 9 |
|
| 10 |
local ret = redis.call('SSCAN', KEYS[2] .. '_keys', cursor, 'COUNT', tonumber(KEYS[4])) |
| 11 |
|
| 12 |
local new_cursor = tonumber(ret[1]) |
| 13 |
local nkeys = #ret[2] |
| 14 |
local learns = 0 |
| 15 |
for _, key in ipairs(ret[2]) do |
| 16 |
learns = learns + (tonumber(redis.call('HGET', key, KEYS[3])) or 0) |
| 17 |
end |
| 18 |
|
| 19 |
return { new_cursor, nkeys, learns } |