hi,
我在openresty中使用resty-redis从redis list中读数据,相关代码如下:
local res, err = rds:brpop(config.source_redis[redis_index].list, 10)
此段代码会放入一个循环中不断从redis中取数据
代码运行了一个月以上都没有问题,昨天突然报错导致进程挂掉,错误内容如下:
2017/07/02 11:30:17 [error] 22812#0: *6138944 lua entry thread aborted: runtime error: /home/data/serving/tiger/openresty/lualib/resty/redis.lua:167:
attempt to compare nil with number
stack traceback:
coroutine 0:
/home/data/serving/tiger/openresty/lualib/resty/redis.lua: in function 'brpop'
/home/data/serving/tiger/lua/source/source_redis.lua:23: in function </home/data/serving/tiger/lua/source/source_redis.lua:8>, context: ngx.ti
mer
看起来是brpop调用时在内部发生了错误,应该不是在brpop返回后我处理不得当造成的
我查看了对应代码,是在_read_reply函数的如下位置出错的:
elseif prefix == 42 then -- char '*'
local n = tonumber(sub(line, 2))
-- print("multi-bulk reply: ", n)
if n < 0 then
return null
end
在n < 0做比较时报错,n是nil
我猜测可能是网络问题导致接收到的数据格式错误导致的
我可以修改代码判断n是否为nil来规避这个问题,但是我想请教以下各位,这个错误的具体原因是什么?是不是我使用的有问题?