23 lines
767 B
Lua
23 lines
767 B
Lua
local records_key = KEYS[1]
|
|
|
|
local now_ms = tonumber(ARGV[1])
|
|
local proxy_id = ARGV[2]
|
|
|
|
if not now_ms or now_ms <= 0 or type(proxy_id) ~= 'string' or proxy_id == '' then
|
|
return cjson.encode({status = 'invalid'})
|
|
end
|
|
|
|
local raw = redis.call('HGET', records_key, proxy_id)
|
|
if not raw then
|
|
return cjson.encode({status = 'not_found'})
|
|
end
|
|
local decoded, record = pcall(cjson.decode, raw)
|
|
if not decoded or type(record) ~= 'table' or type(record.sourceUpstream) ~= 'string' or
|
|
record.sourceUpstream == '' or type(record.expiresAtMs) ~= 'number' then
|
|
return cjson.encode({status = 'invalid'})
|
|
end
|
|
if record.expiresAtMs <= now_ms then
|
|
return cjson.encode({status = 'not_found'})
|
|
end
|
|
return cjson.encode({status = 'ok', upstream = record.sourceUpstream})
|