我的用例这样写:
....
local blocked = false
....
local function blpop()
local res, err = red:blpop('wsmsg', 100)
if res then
local bytes, err = wb:send_text(table.concat(res, ':'))
if not bytes then
ngx.log(ngx.ERR, "failed to send text: ", err)
return ngx.exit(444)
end
elseif not res then
ngx.log(ngx.ERR, "failed to blpop wsmsg", err)
end
return false
end
while true do
local data, typ, err = wb:recv_frame()
if wb.fatal then
ngx.log(ngx.ERR, "failed to receive frame: ", err)
return ngx.exit(444)
end
if not data then
local bytes, err = wb:send_ping()
if not bytes then
ngx.log(ngx.ERR, "failed to send ping: ", err)
return ngx.exit(444)
end
elseif typ == "close" then
break
elseif typ == "text" then
local bytes, err = wb:send_text(data)
if not bytes then
ngx.log(ngx.ERR, "failed to send text: ", err)
return ngx.exit(444)
end
end
ngx.log(ngx.CRIT, 'over a loop', ':', typ, ':', data)
if not blocked then
blocked = true
blocked = blpop()
end
end
wb:send_close()
这样在websocket服务中用blpop订阅消息不知道合适不合适, 请指教。
On Tuesday, January 7, 2014 4:36:20 PM UTC+8, Nero.Ping wrote:
2.如果在这个循环中用redis的blpop订阅消息, 这个blpop会不会阻塞当前的循环