If you refer to the Redis EVAL documentation, you can see what rules Redis uses to convert the Lua table to a Redis response:
- Lua table (array) -> Redis multi bulk reply ( truncated to the first nil inside the Lua array, if any )
- Lua table with one ok field -> Redis status message
- Lua table with one err field -> Redis response error
Therefore, except in special cases 2 and 3, Redis assumes that your table is a sequence (that is, a list), which means that it reads retv[1], retv[2], ... until it encounters the nil element (here is the corresponding source code ).
This explains why retv["test"] ignored in your case.
If you change your code to:
local retv = {"This", "is", "a", "bug" } retv[5] = 1000 return retv
Then this extra element is returned:
1) "This" 2) "is" 3) "a" 4) "bug" 5) (integer) 1000
source share