Skip to content

Commit

Permalink
fix load-balancer example and add server_name to cache keys when requ…
Browse files Browse the repository at this point in the history
…ired
  • Loading branch information
fl0ppy-d1sk committed May 7, 2023
1 parent 66921b0 commit 39ace81
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/load-balancer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- REVERSE_PROXY_URL=/
- REVERSE_PROXY_HOST=http://app
- |
CUSTOM_CONF_HTTP_upstream.conf=
CUSTOM_CONF_HTTP_upstream=
upstream app {
server app1:80;
server app2:80;
Expand Down
4 changes: 2 additions & 2 deletions src/common/core/blacklist/blacklist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ function blacklist:kind_to_ele(kind)
end

function blacklist:is_in_cache(ele)
local ok, data = self.cachestore:get("plugin_blacklist_" .. ele)
local ok, data = self.cachestore:get("plugin_blacklist_" .. ngx.ctx.bw.server_name .. ele)
if not ok then
return false, data
end
return true, data
end

function blacklist:add_to_cache(ele, value)
local ok, err = self.cachestore:set("plugin_blacklist_" .. ele, value, 86400)
local ok, err = self.cachestore:set("plugin_blacklist_" .. ngx.ctx.bw.server_name .. ele, value, 86400)
if not ok then
return false, err
end
Expand Down
4 changes: 2 additions & 2 deletions src/common/core/country/country.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ function country:preread()
end

function country:is_in_cache(ip)
local ok, data = self.cachestore:get("plugin_country_cache_" .. ip)
local ok, data = self.cachestore:get("plugin_country_cache_" .. ngx.ctx.bw.server_name .. ip)
if not ok then
return false, data
end
return true, data
end

function country:add_to_cache(ip, country, result)
local ok, err = self.cachestore:set("plugin_country_cache_" .. ip, cjson.encode({country = country, result = result}), 86400)
local ok, err = self.cachestore:set("plugin_country_cache_" .. ngx.ctx.bw.server_name .. ip, cjson.encode({country = country, result = result}), 86400)
if not ok then
return false, err
end
Expand Down
4 changes: 2 additions & 2 deletions src/common/core/greylist/greylist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ function greylist:is_greylisted_ua()
end

function greylist:is_in_cache(ele)
local ok, data = self.cachestore:get("plugin_greylist_" .. ele)
local ok, data = self.cachestore:get("plugin_greylist_" .. ngx.ctx.bw.server_name .. ele)
if not ok then
return false, data
end
return true, data
end

function greylist:add_to_cache(ele, value)
local ok, err = self.cachestore:set("plugin_greylist_" .. ele, value, 86400)
local ok, err = self.cachestore:set("plugin_greylist_" .. ngx.ctx.bw.server_name .. ele, value, 86400)
if not ok then
return false, err
end
Expand Down
4 changes: 2 additions & 2 deletions src/common/core/whitelist/whitelist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ function whitelist:check_cache()
end

function whitelist:is_in_cache(ele)
local ok, data = self.cachestore:get("plugin_whitelist_" .. ele)
local ok, data = self.cachestore:get("plugin_whitelist_" .. ngx.ctx.bw.server_name .. ele)
if not ok then
return false, data
end
return true, data
end

function whitelist:add_to_cache(ele, value)
local ok, err = self.cachestore:set("plugin_whitelist_" .. ele, value, 86400)
local ok, err = self.cachestore:set("plugin_whitelist_" .. ngx.ctx.bw.server_name .. ele, value, 86400)
if not ok then
return false, err
end
Expand Down

0 comments on commit 39ace81

Please sign in to comment.