"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serializePoolsToHash = serializePoolsToHash; exports.parsePoolsFromHash = parsePoolsFromHash; exports.setPoolCache = setPoolCache; exports.getPoolCache = getPoolCache; exports.incrementPoolCache = incrementPoolCache; const keys_1 = require("./keys"); const client_1 = require("./client"); const POOL_TTL_SECONDS = 86400; function serializePoolsToHash(pools) { return { short: String(pools.short), long: String(pools.long), }; } function parsePoolsFromHash(hash) { if (hash.short == null && hash.long == null) return null; return { short: Number(hash.short ?? 0), long: Number(hash.long ?? 0), }; } async function setPoolCache(intervalMinutes, openMs, pools) { const redis = (0, client_1.getRedisClient)(); if (!redis) return; const key = keys_1.redisKeys.pools(intervalMinutes, openMs); await redis.hset(key, serializePoolsToHash(pools)); await redis.expire(key, POOL_TTL_SECONDS); } async function getPoolCache(intervalMinutes, openMs) { const redis = (0, client_1.getRedisClient)(); if (!redis) return null; const key = keys_1.redisKeys.pools(intervalMinutes, openMs); const hash = await redis.hgetall(key); if (!hash || !Object.keys(hash).length) return null; return parsePoolsFromHash(hash); } async function incrementPoolCache(intervalMinutes, openMs, delta) { const redis = (0, client_1.getRedisClient)(); if (!redis) return; const key = keys_1.redisKeys.pools(intervalMinutes, openMs); if (delta.short) await redis.hincrbyfloat(key, 'short', delta.short); if (delta.long) await redis.hincrbyfloat(key, 'long', delta.long); await redis.expire(key, POOL_TTL_SECONDS); } //# sourceMappingURL=poolCache.js.map