# Ads Redis Key Spec (new adType schema) ## Key naming - `box:app:adpool:{adType}` – JSON array scoped exclusively by the Prisma `AdType` enum (no `adsModuleId`). - `app:ad:by-id:{adId}` – JSON object for a single ad, used by placement services and homepage caches. ## Payload schema - All cached entries must consist of the following fields only: `id`, `adType`, `advertiser`, `title`, `adsContent`, `adsCoverImg`, `adsUrl`, `imgSource`, `startDt`, `expiryDt`, `seq`. - Records are included only when `status === 1` and the current epoch-second window satisfies `startDt <= now` and `(expiryDt === 0 || expiryDt >= now)`. - Ordering inside the pool is strictly ascending by `seq`; the array represents that ordering so readers can respect ad priority. - Timestamps (`startDt`, `expiryDt`) stay as BigInt epoch seconds. ## Value type & TTL - `box:app:adpool:{adType}` is stored as a JSON string (array) and has no TTL; cache rebuilds overwrite and regenerate it via the ad-pool service. - `app:ad:by-id:{adId}` is stored as JSON (object) with `EX` of 300 seconds (set from the mgnt cache-sync/warmup services). Readers expect this short TTL to keep per-ad payloads fresh. ## Migration notes - Writers must drop `adsModuleId` completely and rely on `adType` for both pool entries and per-ad caches. Legacy code should map module IDs to ad types only during migration, never store them in Redis.