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