gpt4 book ai didi

lua - HMGET 与 lua-resty-redis 中的数组

转载 作者:IT王子 更新时间:2023-10-29 06:01:06 27 4
gpt4 key购买 nike

我想替换这个命令:

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

  • Lua 5.1 red:hmget('item', unpack(test))
  • Lua 5.2 red:hmget('item', table.unpack(test))

unpack 是一个解开数组样式表的函数,就好像您将其用作一组参数一样。它有点类似于您可能在其他语言中找到的 splat 运算符。

> =unpack{'item:1', 'item:2'}
item:1 item:2

关于lua - HMGET 与 lua-resty-redis 中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20276034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com