Skip to content

feat(no-close): added variable to avoid closing #15

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 1 commit 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: 10 additions & 6 deletions lib/resty/redis/ratelimit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,26 @@ local function redis_commit(red, zone, key, rate, burst, duration)
return nil, err
end

-- put it into the connection pool of size 100,
-- with 10 seconds max idle timeout
local ok, err = red:set_keepalive(10000, 100)
if not ok then
ngx.log(ngx.WARN, "failed to set keepalive: ", err)
if not self.no_close then -- do not close connection if specified not to do so
-- put it into the connection pool of size 100,
-- with 10 seconds max idle timeout
local ok, err = red:set_keepalive(10000, 100)
if not ok then
ngx.log(ngx.WARN, "failed to set keepalive: ", err)
end
end

return res
end


-- local lim, err = class.new(zone, rate, burst, duration)
function _M.new(zone, rate, burst, duration)
function _M.new(zone, rate, burst, duration, no_close)
local zone = zone or "ratelimit"
local rate = rate or "1r/s"
local burst = burst or 0
local duration = duration or 0
local no_close = no_close or false

local scale = 1
local len = #rate
Expand All @@ -189,6 +192,7 @@ function _M.new(zone, rate, burst, duration)
rate = rate,
burst = burst,
duration = duration,
no_close = no_close
}, mt)
end

Expand Down