When I run this code through redis EVAL it return no results. Any idea why this is not working?
redis-cli EVAL "$(cat bug.lua)" 0
local retv = {}
retv["test"] = 1000
return retv
If I initialize the table that value alone gets printed.
$ cat bug.lua
--!/usr/bin/env lua
local retv = {"This", "is", "a", "bug" }
retv["test"] = 1000
return retv
$ redis-cli EVAL "$(cat bug.lua)" 2 a b
1) "This"
2) "is"
3) "a"
4) "bug"
If you refer to the Redis EVAL
documentation you can see what are the rules Redis uses to convert a Lua table into a Redis reply:
So except with special cases 2 and 3, Redis assumes your table is a sequence (i.e list) which means it reads retv[1], retv[2], ...
until it encounters a nil
element (here is the corresponding source code section).
This explains why retv["test"]
is ignored in your case.
If you change your code with:
local retv = {"This", "is", "a", "bug" }
retv[5] = 1000
return retv
Then this additional element gets returned:
1) "This"
2) "is"
3) "a"
4) "bug"
5) (integer) 1000