mirror of
https://github.com/fluencelabs/redis
synced 2025-06-19 04:01:22 +00:00
Scripting: redis.NIL to return nil bulk replies.
Lua arrays can't contain nil elements (see http://www.lua.org/pil/19.1.html for more information), so Lua scripts were not able to return a multi-bulk reply containing nil bulk elements inside. This commit introduces a special conversion: a table with just a "nilbulk" field set to a boolean value is converted by Redis as a nil bulk reply, but at the same time for Lua this type is not a "nil" so can be used inside Lua arrays. This type is also assigned to redis.NIL, so the following two forms are equivalent and will be able to return a nil bulk reply as second element of a three elements array: EVAL "return {1,redis.NIL,3}" 0 EVAL "return {1,{nilbulk=true},3}" 0 The result in redis-cli will be: 1) (integer) 1 2) (nil) 3) (integer) 3
This commit is contained in:
@ -30,6 +30,10 @@ start_server {tags {"scripting"}} {
|
||||
set _ $e
|
||||
} {this is an error}
|
||||
|
||||
test {EVAL - Lua nil reply -> Redis protocol type conversion} {
|
||||
r eval {return {1,redis.NIL,{nilbulk=true},4}} 0
|
||||
} {1 {} {} 4}
|
||||
|
||||
test {EVAL - Lua table -> Redis protocol type conversion} {
|
||||
r eval {return {1,2,3,'ciao',{1,2}}} 0
|
||||
} {1 2 3 ciao {1 2}}
|
||||
|
Reference in New Issue
Block a user