Redis mget在Node.js中使用Lua脚本

问题描述 投票:0回答:1

我正在传递一组键。这里keylist = ['KEY_100', 'KEY_101']我想获取所有键值。但我在说这个错误:node_redis: Deprecated: The EVAL command contains a argument of type Array.github中有一个问题,建议使用toString()并再次解析最后的值。但是我对此感到满意。谁能帮我解决这个问题?

Nodejs:

getDataLua (keylist) {
    console.log('lua keylist:', keylist)
    const getAsync = promisify(this.client.eval).bind(this.client)
    const reply = await getAsync(fs.readFileSync('./lib/test1.lua'), 1, keylist)
    console.log('reply', reply)
    return reply
  }

Lua脚本:

local keys = redis.call('keys', KEYS[1])
local values = redis.call('mget', unpack(keys))
local keyValuePairs = {}
for i = 1, #keys do
  keyValuePairs[i] = .. values[i]
end
return keyValuePairs
javascript node.js redis lua
1个回答
0
投票

您应该做这样的事情:

const reply = await getAsync(fs.readFileSync('./lib/test1.lua'), keylist.length, ...keylist);
© www.soinside.com 2019 - 2024. All rights reserved.