我正在使用nekipelov/redisclient访问Redis,我需要通过一次调用Redis来检索多个哈希数据,以提高性能。
更具体地说,我正在尝试检索多个散列,如下所示:
redis-cli --ldb --eval /tmp/script.lua hash_key1 hash_key2其中script.lua:
local r = {}
for _, v in pairs(KEYS) do
r[#r+1] = redis.call('HGETALL', v)
end
return r但我很难通过nekipelov/redisclient使用EVAL命令来表达上述内容。
我尝试了以下几种方法:
redisclient.command("EVAL", {"/tmp/script.lua", hash_key1, hash_key2}但显然是错误的。
发布于 2017-01-19 18:35:34
我找到了解决方案,问题出现在我如何在redisclient中构造EVAL命令-我将Lua脚本作为文件传递:
const std::string script =
"local r = {} "
"for _, v in pairs(KEYS) do "
"r[#r+1] = redis.call('HGETALL', v) "
"end "
"return r ";
const unsigned int numKeys = 2;
const std::string key1 = "hash_key1";
const std::string key2 = "hash_key2";
result = redisclient.command("EVAL", {script, std::to_string(numKeys), key1, key2});https://stackoverflow.com/questions/41738779
复制相似问题