为什么 Redis return 布尔值用于 lua 脚本中的 HGET?
Why does redis return boolean for HGET in lua script?
这是我的评估命令
eval "local b = redis.call('hget', 'foo', 'baz'); if (type(b) == 'boolean') then return 'boolean' else return 'not a boolean' end" 0 "hello"
这 return 秒 boolean
。但是,如果我 return b
的值,我会得到 (nil)
。这里发生了什么?
来自https://gigacrunch.herokuapp.com/commands/hget
the value associated with field, or nil when field is not present in
the hash or key does not exist
Redis 和 Lua 值之间有一些转换规则 https://cndoc.github.io/redis-doc-cn/cn/commands/eval.html
Redisnil
转换为Luafalse
。所以 b
是错误的。因此 type(b)
是布尔值,所以你 return 一个字符串 'boolean'
.
如果你returnb
你returnfalse
。 Lua false
转换为 Redis nil
.
这是我的评估命令
eval "local b = redis.call('hget', 'foo', 'baz'); if (type(b) == 'boolean') then return 'boolean' else return 'not a boolean' end" 0 "hello"
这 return 秒 boolean
。但是,如果我 return b
的值,我会得到 (nil)
。这里发生了什么?
来自https://gigacrunch.herokuapp.com/commands/hget
the value associated with field, or nil when field is not present in the hash or key does not exist
Redis 和 Lua 值之间有一些转换规则 https://cndoc.github.io/redis-doc-cn/cn/commands/eval.html
Redisnil
转换为Luafalse
。所以 b
是错误的。因此 type(b)
是布尔值,所以你 return 一个字符串 'boolean'
.
如果你returnb
你returnfalse
。 Lua false
转换为 Redis nil
.