Reputation: 21
I have following scnario using lua with redis script
local valuesForMset = {"key_1", "0", "key_2", "0"};
redis.call("MSET", unpack(valuesForMset))
I would expect MGET key_1 to return 0 but instead it returns nil
. I have already tried following as well
local valuesForMset = {"key_1", "key_2"};
redis.call("MSET", unpack(valuesForMset))
And result is same. Has anyone used lua for MSET? If yes how did you achieve setting key-value with MSET.
Thank you in advance.
Upvotes: 2
Views: 618
Reputation: 1194
You have not created a table with values, you have created the Lua equivalent of a set in this line
local valuesForMset = {"key_1", "0", "key_2", "0"};
To be a Lua table with key-value pairs it should be
local valuesForMset = {}
valuesForMset["key_1"] = 0
valuesForMset["key_2"] = 0
Your original code created a table with four keys all with the nil
value.
Upvotes: 2