2

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.

1 Answers1

2

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.

JimmyNJ
  • 1,134
  • 1
  • 8
  • 23
  • For lua script that is executed at redis it is not possible to do local `valuesForMset = {} valuesForMset["key_1"] = 0 valuesForMset["key_2"] = 0` . This has been answered here : https://stackoverflow.com/questions/24298763/redis-lua-tables-as-return-values-why-is-this-not-working . Thank you for taking time to answer. – human-without-a-name Oct 21 '22 at 06:19
  • @barnstola - Use the appropriate syntax within Redis, then, however my answer stands. – JimmyNJ Oct 21 '22 at 21:24