proxy-pool/internal/adapters/redisactivity/scripts/upstream_lookup.lua
youfak 65aee12d51
Some checks are pending
ci / proto (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
ci / integration (push) Waiting to run
feat: wire checker observations into controller
2026-07-31 18:25:07 +08:00

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})