127.0.0.1:6379> eval "local substring = redis.call('hget',KEYS[1],KEYS[2]) if not substring then return false end substring = cjson.decode(substring) local result = {} for _, v in ipairs(ARGV) do table.insert(result,substring[v] or false) end return result" 2 team wyc age len name
1) "444"
2) (nil)
3) "wyycc"
OpenResty的lua_resty_redis返回为空的判断
local res, err = red:get("dog")
if not res then
ngx.say("failed to get dog: ", err)
return
end
if res == ngx.null then
ngx.say('res is null')
else
ngx.say('res is not empty')
end
ngx.say(type(res))
ngx.say(res)
结果:
res is null
userdata
null
lua_resty_redis的redis操作返回的数据打印出来是null,但是不等同于lua中的nil,也不能直接和null比较,里面是lua的8中数据类型中的userdata。文档中已经有描述了:A non-nil Redis "bulk reply" results in a Lua string as the return value. A nil bulk reply results in a ngx.null return value. lua_resty_redis文档