我想替换这个命令:
red:hmget('item', 'item:1', 'item:2')
用类似的东西:
local test = {'item:1', 'item:2'}
red:hmget('item', test)
但是,当我尝试此操作时出现错误 (string expected, got table)
。我如何在 Lua for Redis 中格式化它?
最佳答案
根据您使用的 Lua 版本,您需要使用 unpack
。
unpack
是一个解开数组样式表的函数,就好像您将其用作一组参数一样。它有点类似于您可能在其他语言中找到的 splat 运算符。
> =unpack{'item:1', 'item:2'}
item:1 item:2
关于lua - HMGET 与 lua-resty-redis 中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20276034/