]> git.saurik.com Git - redis.git/commitdiff
Scripting: redis.NIL to return nil bulk replies.
authorantirez <antirez@gmail.com>
Fri, 28 Sep 2012 12:19:15 +0000 (14:19 +0200)
committerantirez <antirez@gmail.com>
Fri, 28 Sep 2012 12:26:20 +0000 (14:26 +0200)
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


No differences found