Skip to content

Commit

Permalink
fix(rate-limiting) effectively use the selected Redis database
Browse files Browse the repository at this point in the history
From #2481
  • Loading branch information
subnetmarco authored and thibaultcha committed May 2, 2017
1 parent 62341da commit 78d0389
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions kong/plugins/rate-limiting/policies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ return {
end
end

if conf.redis_database ~= nil and conf.redis_database > 0 then
local ok, err = red:select(conf.redis_database)
if not ok then
ngx_log(ngx.ERR, "failed to change Redis database: ", err)
return nil, err
end
end

local periods = timestamp.get_timestamps(current_timestamp)
local cache_key = get_local_key(api_id, identifier, periods[name], name)
local current_metric, err = red:get(cache_key)
Expand Down
8 changes: 8 additions & 0 deletions kong/plugins/response-ratelimiting/policies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ return {
end
end

if conf.redis_database ~= nil and conf.redis_database > 0 then
local ok, err = red:select(conf.redis_database)
if not ok then
ngx_log(ngx.ERR, "failed to change Redis database: ", err)
return nil, err
end
end

local periods = timestamp.get_timestamps(current_timestamp)
local cache_key = get_local_key(api_id, identifier, periods[period], name, period)
local current_metric, err = red:get(cache_key)
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/24-rate-limiting/04-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local cjson = require "cjson"
local REDIS_HOST = "127.0.0.1"
local REDIS_PORT = 6379
local REDIS_PASSWORD = ""
local REDIS_DATABASE = 0
local REDIS_DATABASE = 1

local SLEEP_TIME = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local timestamp = require "kong.tools.timestamp"
local REDIS_HOST = "127.0.0.1"
local REDIS_PORT = 6379
local REDIS_PASSWORD = ""
local REDIS_DATABASE = 0
local REDIS_DATABASE = 1

local SLEEP_TIME = 1

Expand Down

0 comments on commit 78d0389

Please sign in to comment.