How to insert key value object into lua table inside redis

local users = {}
table.insert(users, {['uid']= 'xxx'})

How to insert object into table in Lua script. When I try to insert, Lua returns empty array, with empty array inside "[[]]".

table.insert(users, 'xxx')

When I insert string, it is properly returned. "['xxx']"

I'm running Lua inside redis. In node.

JavaScript example would be:

const arr = []
arr.push({uid: 'xxx'})

Upvotes: 3

Views: 5797

Answers (1)

Mike V.
Mike V.

Reputation: 2205

try this method to get element : users[1].uid or users[1].['uid']

local users = {}
table.insert(users, { ['uid'] = 'xxx'})
table.insert(users, { uid = 'yyy'})

print(users[1].uid)
print(users[2].uid)

output:

xxx
yyy

Upvotes: 4

Related Questions