aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/redis_scripts/neural_train_size.lua
blob: 45ad6a931fbbf74f1f450718477ab0e7d6912af8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Lua script that checks if we can store a new training vector
-- Uses the following keys:
-- key1 - ann key
-- returns nspam,nham (or nil if locked)

local prefix = KEYS[1]
local locked = redis.call('HGET', prefix, 'lock')
if locked then
  local host = redis.call('HGET', prefix, 'hostname') or 'unknown'
  return string.format('%s:%s', host, locked)
end
local nspam = 0
local nham = 0

local ret = redis.call('SCARD', prefix .. '_spam_set')
if ret then
  nspam = tonumber(ret)
end
ret = redis.call('SCARD', prefix .. '_ham_set')
if ret then
  nham = tonumber(ret)
end

return { nspam, nham }