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.
This commit is contained in:
kyuuseiryuu 2026-03-03 18:23:12 +09:00
parent 58edba247d
commit 0ac1d2e31d
3 changed files with 8 additions and 5 deletions

View File

@ -1,2 +1,3 @@
KAIQIUCC_TOKEN=''
REDIS=''
REDIS=''
REDIS_CACHE_HOUR=''

View File

@ -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<Record<string, string>> => {
const jobs = uids.map(async uid => {

View File

@ -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<IEventInfo[]> {
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);
}