Debian Codegraph @

lualib/redis_scripts/neural_save_unlock.lua

raw
1 -- Lua script to save and unlock ANN in redis
2 -- Uses the following keys and argv
3 -- key1 - prefix for ANN
4 -- key2 - prefix for profile
5 -- key3 - old key
6 -- argv1 - compressed ANN
7 -- argv2 - profile as JSON
8 -- argv3 - expire in seconds
9 -- argv4 - current time
10 -- argv5 - ROC Thresholds
11 -- argv6 - optional PCA
12 -- argv7 - optional providers_meta (JSON)
13 -- argv8 - optional norm_stats (JSON)
14 local now = tonumber(ARGV[4])
15 redis.call('ZADD', KEYS[2], now, ARGV[2])
16 redis.call('HSET', KEYS[1], 'ann', ARGV[1])
17 redis.call('HSET', KEYS[1], 'roc_thresholds', ARGV[5])
18 if ARGV[6] and ARGV[6] ~= '' then
19 redis.call('HSET', KEYS[1], 'pca', ARGV[6])
20 end
21 if ARGV[7] and ARGV[7] ~= '' then
22 redis.call('HSET', KEYS[1], 'providers_meta', ARGV[7])
23 end
24 if ARGV[8] and ARGV[8] ~= '' then
25 redis.call('HSET', KEYS[1], 'norm_stats', ARGV[8])
26 end
27 redis.call('HDEL', KEYS[1], 'lock')
28 redis.call('HDEL', KEYS[3], 'lock')
29 redis.call('HSET', KEYS[3], 'obsolete', '1')
30 redis.call('EXPIRE', KEYS[3], 600)
31 redis.call('EXPIRE', KEYS[1], tonumber(ARGV[3]))
32 -- expire in 10m, to not face race condition with other rspamd replicas refill deleted keys
33 redis.call('EXPIRE', KEYS[3] .. '_spam_set', 600)
34 redis.call('EXPIRE', KEYS[3] .. '_ham_set', 600)
35 return 1