Skip to content

bugfix: connection is closed after the blpop and brpop calls time out #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/resty/redis.lua
Original file line number Diff line number Diff line change
@@ -52,6 +52,9 @@ local sub_commands = {
"subscribe", "psubscribe"
}

local blocking_commands = {
"blpop", "brpop"
}

local unsub_commands = {
"unsubscribe", "punsubscribe"
@@ -243,7 +246,7 @@ _M.close = close
local function _read_reply(self, sock)
local line, err = sock:receive()
if not line then
if err == "timeout" and not rawget(self, "_subscribed") then
if err == "timeout" and not rawget(self, "_subscribed") and not rawget(self, "_blocking") then
sock:close()
end
return nil, err
@@ -502,6 +505,17 @@ for i = 1, #common_cmds do
end
end

for i = 1, #blocking_commands do
local cmd = blocking_commands[i]

_M[cmd] =
function (self, ...)
if not rawget(self, "_blocking") then
self._blocking = true
end
return do_cmd(self, cmd, ...)
end
end

local function handle_subscribe_result(self, cmd, nargs, res)
local err
2 changes: 1 addition & 1 deletion t/count.t
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ __DATA__
ngx.say("size: ", n)
';
--- response_body
size: 56
size: 58
--- no_error_log
[error]