1

可変数のキーで zunionstore を呼び出す必要がある lua スクリプトがあります。次のコードを実行しようとしています。

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.call("zunionstore"...) コマンドに渡すにはどうすればよいでしょうか?

前もって感謝します!

4

1 に答える 1

0

私がこれを解決した方法は次のとおりです。

for i=0,#array,1 do
    local tmp = {'zunionstore', key, #array[i], unpack(array[i])}
    redis.call(unpack(tmp))
end
于 2014-06-10T18:28:23.133 に答える