edit visibility of Job members and integration of a generic checker for nginx

This commit is contained in:
bunkerity
2021-07-22 23:07:35 +02:00
parent 9a207dfdc5
commit 0dc2a5ec25
8 changed files with 98 additions and 120 deletions

View File

@@ -1,41 +1,42 @@
local M = {}
local redis = require "resty.redis"
local mt = { __index = M }
function M.new(self, name, data_dict, redis_client, type)
return selfmetatable({
return setmetatable({
__name = name,
__data_dict = data_dict,
__redis_client = redis_client,
__type = type
})
}, mt)
end
function M.check(self, data) :
function M.check(self, data)
-- without redis
if self.__data_dict ~= nil and redis_client == nil then
if self.__data_dict ~= nil and self.__redis_client == nil then
if self.__type == "simple" then
local value, flags = self.__data_dict:get(data)
return ~= nil
else if self.__type == "match" then
return value ~= nil
elseif self.__type == "match" then
local patterns = self.__data_dict:get_keys(0)
for i, pattern in ipairs(patterns) do
if string.match(data, pattern) then
return true
end
end
return false
end
-- with redis
else if data_dict == nil and redis_client ~= nil then
elseif self.__data_dict == nil and self.__redis_client ~= nil then
if self.__type == "simple" then
local res, err = self.__redis_client:get(self.__name .. "_" .. data)
return res and res ~= ngx.null
else if self.__type == "match" then
elseif self.__type == "match" then
local patterns = self.__redis_client:keys(self.__name .. "_*")
if patterns then
for i, pattern in ipairs(patterns) do
if string.match(data, pattern) do
if string.match(data, pattern) then
return true
end
end
@@ -45,4 +46,6 @@ function M.check(self, data) :
return false
end
return M