From 0ac1d2e31dc1d405bfda3beacbc892e2da1bcee2 Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Tue, 3 Mar 2026 18:23:12 +0900 Subject: [PATCH] feat: add REDIS_CACHE_HOUR to environment variables and update timeout usage - Added REDIS_CACHE_HOUR to .env.example and src/utils/server.ts. - Updated TIMEOUT usage in src/services/uidScoreStore.ts and src/utils/server.ts to use REDIS_CACHE_HOUR. --- .env.example | 3 ++- src/services/uidScoreStore.ts | 4 ++-- src/utils/server.ts | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 4fd88dc..057142c 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ KAIQIUCC_TOKEN='' -REDIS='' \ No newline at end of file +REDIS='' +REDIS_CACHE_HOUR='' \ No newline at end of file diff --git a/src/services/uidScoreStore.ts b/src/services/uidScoreStore.ts index 486267d..6f8b387 100644 --- a/src/services/uidScoreStore.ts +++ b/src/services/uidScoreStore.ts @@ -1,8 +1,8 @@ -import { redis, xcxApi } from '../utils/server'; +import { redis, REDIS_CACHE_HOUR, xcxApi } from '../utils/server'; const getKey = (uid: string) => `my-kaiqiuwang:uid-score:${uid}`; -const TIMEOUT = 60 * 60 * 24; // 24h; +const TIMEOUT = 60 * 60 * REDIS_CACHE_HOUR; // 24h; export const getUidScore = async (uids: string[]): Promise> => { const jobs = uids.map(async uid => { diff --git a/src/utils/server.ts b/src/utils/server.ts index a92c651..7b22191 100644 --- a/src/utils/server.ts +++ b/src/utils/server.ts @@ -15,6 +15,8 @@ if (!REQUIRED_ENVS.every(v => !!v)) { process.exit(1); } +export const REDIS_CACHE_HOUR = Number(process.env.REDIS_CACHE_HOUR) ?? 8; + export const xcxApi = new XCXAPI(process.env.KAIQIUCC_TOKEN ?? ''); export const redis = new RedisClient(process.env.REDIS ?? ''); @@ -44,7 +46,7 @@ export async function listEvent(tagid: string): Promise { let html = await redis.get(key); if (!html) { html = await fetchEventListHTML(tagid); - await redis.setex(key, 60 * 60 * 72, html); + await redis.setex(key, 60 * 60 * REDIS_CACHE_HOUR, html); } return parseEventList(html); } @@ -118,7 +120,7 @@ export async function getMatchInfo(matchId: string) { let html = await redis.get(key); if (!html) { html = await fetchEventContentHTML(matchId); - await redis.setex(key, 60 * 72, html); + await redis.setex(key, 60 * 60 * REDIS_CACHE_HOUR, html); } return parseEventInfo(html); }