Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scripting 使用变量键从Lua调用Redis zunionstore_Scripting_Lua_Redis_In Memory Database_Set Theory - Fatal编程技术网

Scripting 使用变量键从Lua调用Redis zunionstore

Scripting 使用变量键从Lua调用Redis zunionstore,scripting,lua,redis,in-memory-database,set-theory,Scripting,Lua,Redis,In Memory Database,Set Theory,我有一个lua脚本,它需要在不同数量的键上调用zunionstore。 我正在尝试执行以下代码: local args = redis.call("zrange", "weight", 0, -1, "WITHSCORES") local r,w local count = 0 local cmd = ' ' for i=1,#args,2 do cmd = cmd .. args[i] .. ":weight " -- building up a list of zsets c

我有一个lua脚本,它需要在不同数量的键上调用zunionstore。 我正在尝试执行以下代码:

local args = redis.call("zrange", "weight", 0, -1, "WITHSCORES")
local r,w
local count = 0
local cmd = ' '
for i=1,#args,2 do
    cmd = cmd .. args[i] .. ":weight " -- building up a list of zsets
    count = count + 1
end
redis.call("zunionstore", "p2_test_set", count, cmd)
重点是:

cmd = cmd .. args[i] .. ":weight "
这将生成键列表和实际调用:

redis.call("zunionstore", "p2_test_set", count, cmd)
但是,在执行时,我得到以下错误:

redis-cli EVAL "$(cat p2.lua)" 0
(error) ERR Error running script (call to f_6dc6501103ea64a02798af1cc9132f8337cdcad4): @user_script:9: ERR syntax error
那么,如何将lua脚本中计算的可变数量的键传递给redis.callzunionstore。。。指挥部


提前谢谢

我解决这个问题的方法是:

for i=0,#array,1 do
    local tmp = {'zunionstore', key, #array[i], unpack(array[i])}
    redis.call(unpack(tmp))
end

您是否尝试过使用实际参数调用脚本?在您的示例中,您没有传递任何密钥,因此实际上是在没有密钥的情况下调用zunionstore。嘿-我不知道运行时的密钥,所以我不确定如何将它们传递给LUA脚本,如果这是您要问的…我的意思是-您确定“权重”中有任何内容吗?是的,已验证。不过谢谢。当然-没有真正的测试,我就不会有我的lappy w。现在我大胆猜测,将args传递给zunionstore需要使用一个表,而不是作为串联字符串。