]> git.saurik.com Git - redis.git/commit
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)
commit6dd1693c0e4bfae0ca0983b2a0bf70ae234a6bcb
treeabe9e4ab7e059abafa19d3762a8da2553f5ec022
parentdb100c4671c9576710c762f3fa36ab58757236a6
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
src/scripting.c
tests/unit/scripting.tcl