HMGET with an array in lua-resty-redis
lua, redis
Solution
Depending upon which version of Lua you're using, you'll want to make use of `unpack`.
- Lua 5.1 `red:hmget('item', unpack(test))`
- Lua 5.2 `red:hmget('item', table.unpack(test))`
`unpack` is a function which unravels an array-style table as if you were using it like a set of arguments. It is somewhat similar to a splat operator that you might find in other languages.
> =unpack{'item:1', 'item:2'}
item:1 item:2
Problem
I want to replace this command: ``` red:hmget('item', 'item:1', 'item:2') ``` With something like: ``` local test = {'item:1', 'item:2'} red:hmget('item', test) ``` But, I'm getting an error `(string expected, got table)` when I try this. How can I format this in Lua for Redis?