-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Hi, I have set up everything and I constantly get error 503
This is my limit block
access_by_lua_block {
local ratelimit = require "resty.redis.ratelimit"
local lim, err = ratelimit.new("one", "2r/s")
if not lim then
ngx.log(ngx.ERR,
"failed to instantiate a resty.redis.ratelimit object: ", err)
return ngx.exit(500)
end
-- NOTICE: the following call must be per-request.
-- local redis = require "resty.redis"
-- local red = redis:new()
-- red:set_timeout(1000)
-- local ok, err = red:connect("65.108.155.90", 6379)
-- if not ok then
-- ngx.log(ngx.ERR, "failed to connect redis: ", err)
-- return ngx.exit(500)
-- end
local red = { host = "65.108.155.90", port = 6379, timeout = 1 }
local key = ngx.var.binary_remote_addr
local delay, err = lim:incoming(key, red)
if not delay then
if err == "rejected" then
return ngx.exit(503)
end
ngx.log(ngx.ERR, "failed to limit req: ", err)
return ngx.exit(500)
end
if delay >= 0.001 then
-- the 2nd return value holds the number of excess requests
-- per second for the specified key.
local excess = err
ngx.sleep(delay)
end
}
why do I always have err == rejected? Do I miss something here..
gotosre and sagarkivale101
Metadata
Metadata
Assignees
Labels
No labels