Debian Codegraph @

lualib/redis_scripts/bayes_cache_check.lua

raw
1 -- Lua script to perform cache checking for bayes classification
2 -- This script accepts the following parameters:
3 -- key1 - cache id
4 -- argv1 - configuration table in message pack
5
6 local cache_id = KEYS[1]
7 local conf = cmsgpack.unpack(ARGV[1])
8 cache_id = string.sub(cache_id, 1, conf.cache_elt_len)
9
10 -- Try each prefix that is in Redis
11 for i = 0, conf.cache_max_keys do
12 local prefix = conf.cache_prefix .. string.rep("X", i)
13 local have = redis.call('HGET', prefix, cache_id)
14
15 if have then
16 -- Return the raw string value (class name, e.g. "spam", "ham", "transactional").
17 -- Previously tonumber() was used here, but 64-bit integer class IDs exceed
18 -- Lua's 53-bit double precision, corrupting the value for multiclass classifiers.
19 return have
20 end
21 end
22
23 return nil