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:
parent
58edba247d
commit
0ac1d2e31d
@ -1,2 +1,3 @@
|
|||||||
KAIQIUCC_TOKEN=''
|
KAIQIUCC_TOKEN=''
|
||||||
REDIS=''
|
REDIS=''
|
||||||
|
REDIS_CACHE_HOUR=''
|
||||||
@ -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 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>> => {
|
export const getUidScore = async (uids: string[]): Promise<Record<string, string>> => {
|
||||||
const jobs = uids.map(async uid => {
|
const jobs = uids.map(async uid => {
|
||||||
|
|||||||
@ -15,6 +15,8 @@ if (!REQUIRED_ENVS.every(v => !!v)) {
|
|||||||
process.exit(1);
|
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 xcxApi = new XCXAPI(process.env.KAIQIUCC_TOKEN ?? '');
|
||||||
|
|
||||||
export const redis = new RedisClient(process.env.REDIS ?? '');
|
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);
|
let html = await redis.get(key);
|
||||||
if (!html) {
|
if (!html) {
|
||||||
html = await fetchEventListHTML(tagid);
|
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);
|
return parseEventList(html);
|
||||||
}
|
}
|
||||||
@ -118,7 +120,7 @@ export async function getMatchInfo(matchId: string) {
|
|||||||
let html = await redis.get(key);
|
let html = await redis.get(key);
|
||||||
if (!html) {
|
if (!html) {
|
||||||
html = await fetchEventContentHTML(matchId);
|
html = await fetchEventContentHTML(matchId);
|
||||||
await redis.setex(key, 60 * 72, html);
|
await redis.setex(key, 60 * 60 * REDIS_CACHE_HOUR, html);
|
||||||
}
|
}
|
||||||
return parseEventInfo(html);
|
return parseEventInfo(html);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user