files['/**/lualib/redis_scripts/**'].globals = {
'redis',
'KEYS',
+ 'ARGV',
'cjson',
'cmsgpack',
}
lua_redis.exec_redis_script(classify_script_id,
{ task = task, is_write = false, key = expanded_key },
- classify_redis_cb, { expanded_key, script_class_labels, stat_tokens })
+ classify_redis_cb, { expanded_key }, { script_class_labels, stat_tokens })
end
end
lua_redis.exec_redis_script(learn_script_id,
{ task = task, is_write = true, key = expanded_key },
learn_redis_cb,
- { expanded_key, script_class_label, symbol, tostring(is_unlearn), stat_tokens, maybe_text_tokens })
+ { expanded_key }, { script_class_label, symbol, tostring(is_unlearn), stat_tokens, maybe_text_tokens })
else
lua_redis.exec_redis_script(learn_script_id,
{ task = task, is_write = true, key = expanded_key },
- learn_redis_cb, { expanded_key, script_class_label, symbol, tostring(is_unlearn), stat_tokens })
+ learn_redis_cb, { expanded_key }, { script_class_label, symbol, tostring(is_unlearn), stat_tokens })
end
end
end
lua_util.debugm(N, task, 'checking cache: %s', cache_id)
lua_redis.exec_redis_script(check_script_id,
{ task = task, is_write = false, key = cache_id },
- classify_redis_cb, { cache_id, packed_conf })
+ classify_redis_cb, { cache_id }, { packed_conf })
end
end
lua_redis.exec_redis_script(learn_script_id,
{ task = task, is_write = true, key = cache_id },
learn_redis_cb,
- { cache_id, class_name, packed_conf })
+ { cache_id }, { class_name, packed_conf })
end
end
-- Lua script to perform cache checking for bayes classification
-- This script accepts the following parameters:
-- key1 - cache id
--- key2 - configuration table in message pack
+-- argv1 - configuration table in message pack
local cache_id = KEYS[1]
-local conf = cmsgpack.unpack(KEYS[2])
+local conf = cmsgpack.unpack(ARGV[1])
cache_id = string.sub(cache_id, 1, conf.cache_elt_len)
-- Try each prefix that is in Redis
-- Lua script to perform cache learning for bayes classification (multi-class)
-- This script accepts the following parameters:
-- key1 - cache id
--- key2 - class name string (e.g. "spam", "ham", "transactional")
--- key3 - configuration table in message pack
+-- argv1 - class name string (e.g. "spam", "ham", "transactional")
+-- argv2 - configuration table in message pack
--
-- The cache value stored in Redis is the class name string. A numeric class_id
-- hash was used previously, but uint64_t values > 2^53 lose precision when
-- unreliable for arbitrary multiclass names.
local cache_id = KEYS[1]
-local class_name = KEYS[2]
-local conf = cmsgpack.unpack(KEYS[3])
+local class_name = ARGV[1]
+local conf = cmsgpack.unpack(ARGV[2])
-- Store the class name directly as the cache value
local cache_value = class_name
-- Lua script to perform bayes classification (multi-class)
-- This script accepts the following parameters:
-- key1 - prefix for bayes tokens (e.g. for per-user classification)
--- key2 - class labels: table of all class labels as "TABLE:label1,label2,..."
--- key3 - set of tokens encoded in messagepack array of strings
+-- argv1 - class labels: table of all class labels as "TABLE:label1,label2,..."
+-- argv2 - set of tokens encoded in messagepack array of strings
local prefix = KEYS[1]
-local class_labels_arg = KEYS[2]
-local input_tokens = cmsgpack.unpack(KEYS[3])
+local class_labels_arg = ARGV[1]
+local input_tokens = cmsgpack.unpack(ARGV[2])
-- Parse class labels (always expect TABLE: format)
local class_labels = {}
-- Lua script to perform bayes learning (multi-class)
-- This script accepts the following parameters:
-- key1 - prefix for bayes tokens (e.g. for per-user classification)
--- key2 - class label string (e.g. "S", "H", "T")
--- key3 - string symbol
--- key4 - boolean is_unlearn
--- key5 - set of tokens encoded in messagepack array of strings
--- key6 - set of text tokens (if any) encoded in messagepack array of strings (size must be twice of `KEYS[5]`)
+-- argv1 - class label string (e.g. "S", "H", "T")
+-- argv2 - string symbol
+-- argv3 - boolean is_unlearn
+-- argv4 - set of tokens encoded in messagepack array of strings
+-- argv5 - set of text tokens (if any) encoded in messagepack array of strings (size must be twice of `ARGV[4]`)
local prefix = KEYS[1]
-local class_label = KEYS[2]
-local symbol = KEYS[3]
-local is_unlearn = KEYS[4] == 'true' and true or false
-local input_tokens = cmsgpack.unpack(KEYS[5])
+local class_label = ARGV[1]
+local symbol = ARGV[2]
+local is_unlearn = ARGV[3] == 'true' and true or false
+local input_tokens = cmsgpack.unpack(ARGV[4])
local text_tokens
-if KEYS[6] then
- text_tokens = cmsgpack.unpack(KEYS[6])
+if ARGV[5] then
+ text_tokens = cmsgpack.unpack(ARGV[5])
end
-- Handle backward compatibility for boolean values
return 3 + len;
}
else {
- return 4 + len;
+ return 5 + len;
}
}