Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redis Lua脚本Redis.call(';get';,';不存在';)返回值_Lua_Redis_Eval - Fatal编程技术网

Redis Lua脚本Redis.call(';get';,';不存在';)返回值

Redis Lua脚本Redis.call(';get';,';不存在';)返回值,lua,redis,eval,Lua,Redis,Eval,以下Redis Lua脚本似乎返回的是false而不是nil,这与文档中的说法相矛盾: > eval "local r = redis.call('get', 'none'); if r==nil then return 42 end" 0 (nil) > eval "local r = redis.call('get', 'none'); if r==false then return 42 end" 0 (integer) 42 > eval "local r = redi

以下Redis Lua脚本似乎返回的是
false
而不是
nil
,这与文档中的说法相矛盾:

> eval "local r = redis.call('get', 'none'); if r==nil then return 42 end" 0
(nil)
> eval "local r = redis.call('get', 'none'); if r==false then return 42 end" 0
(integer) 42
> eval "local r = redis.call('get', 'none'); if not r then return 42 end" 0
(integer) 42
第一个
eval
在条件
r==nil
下失败,第二个
eval
似乎证明返回值是
false

使用
notr
似乎是我手头上最安全的选择,但是文档中说
GET
命令将返回
nil

其他人是否已经观察到并依赖于这样一个事实:检查返回
nil
的命令的最安全的Redis Lua脚本是使用
而不是r

好的,深入研究,Redis
nil
在Lua脚本中转换为
false

Redis到Lua转换表

  • Redis整数回复->Lua数字
  • Redis批量回复->Lua字符串
  • Redis多批量回复->Lua表(可能嵌套了其他Redis数据类型)
  • Redis status reply->Lua表格,带有一个包含状态的ok字段
  • Redis error reply->Lua表,带有一个包含错误的err字段
  • Redis Nil批量回复和Nil多批量回复->Lua假布尔类型

隐马尔可夫模型。。。Redis里的某种恐尼症?