The Lua fragment:
redis.call("get", i)
Redis' GET
method never returns nil, but it returns a boolean value (false) if no key exists.
Change your code to:
local function test(i)
if (i==nil) then
return 'isnil ' .. i
end
local ch = redis.call("get", i)
if (ch==nil or (type(ch) == "boolean" and not ch)) then
return ("ch is nil or false")
else
return "isthere '" .. ch .. "'"
end
end
return (test(KEYS[1]))
or even simpler (Lua equality checking between different types is allowed, always returns false):
local function test(i)
if (i==nil) then
return 'isnil ' .. i
end
local ch = redis.call("get", i)
if (ch==false) then
return ("ch is false")
else
return "isthere '" .. ch .. "'"
end
end
return (test(KEYS[1]))
If you play around with it a bit more, you'll see that you can get it even simpler than that, but you'll get the point.
Hope this helps, TW