in scripts/lua/lib/redis.lua [712:761]
function _M.optimizedLookup(red, tenant, path)
if CACHING_ENABLED then
local cached = c:get(utils.concatStrings({'fastmap:', tenant, ':', path}))
if cached ~= nil then
return cached
end
end
local script = [[
local tenant = ']] .. tenant .. [['
local path = ']] .. path .. [['
if redis.call('EXISTS', 'resources:' .. tenant .. ':' .. path) ~= 0 then
return 'resources:' .. tenant .. ':' .. path
end
local currStr = 'fastmap:' .. tenant
path = string.match(path, '[^?]*')
local exp_path = string.gmatch(path, '[^/]*')
local path = {}
for i in exp_path do
if i ~= nil and i ~= '' then
table.insert(path, i)
end
end
for i,v in ipairs(path) do
if redis.call('EXISTS', currStr .. '/' .. v) == 1 then
currStr = currStr .. '/' .. v
elseif redis.call('EXISTS', currStr .. '/.*') == 1 then
currStr = currStr .. '/.*'
else
return 0
end
end
return redis.call('GET', currStr)
]]
if red == nil then
red = _M.init()
end
local result = red:eval(script, 0)
if type(result) ~= 'string' or result == '' then
return nil, red
end
ngx.var.gatewayPath = result:gsub(utils.concatStrings({'resources:', tenant, ':'}), '')
if CACHING_ENABLED then
c:set(utils.concatStrings({'fastmap:', tenant, ':', path}), result, CACHE_TTL)
end
return result, red
end