Untitled
unknown
plain_text
4 months ago
2.6 kB
3
Indexable
@Cron(CronExpression.EVERY_DAY_AT_5AM) public async removeMatchesIdInCache(): Promise<void> { const matchEndedIdsRemove: string[] = []; const matchIdsDailyRemove: Set<string> = new Set(); const matchIdsIncidentRemove: string[] = []; const date = new Date(); const today: string = format(date, "yyyyMMdd"); const today_: string = format(date, "yyyy-MM-dd"); const yesterday = format(subDays(date, 1), 'yyyy-MM-dd'); const pipeline = this.redisService.getClient().pipeline(); const time = Math.floor(date.setHours(0, 0, 0, 0) / 1000); const [matchesEndedInCache, matchesDailyCache, matchesIncidentCornerInCache] = await Promise.all([ this.redisService.hmgetAll(RedisKey.MatchEndedToday), this.redisService.hmgetAll(RedisKey.MatchDaily), this.redisService.hgetall<ITSIncident[]>(RedisKey.MatchesIncidentCorner), ]); footballFlagSendMsgSharing.clear(); this.competitionLogoCache.clear(); this.teamLogoCache.clear(); this.countryLogoCache.clear(); for (const key of Object.keys(matchesEndedInCache)) { const obj: ITSMatchLiveEndedCache = JSON.parse(matchesEndedInCache[key]); if (obj.date !== today) { matchEndedIdsRemove.push(key); matchesEndedToDaySharing.delete(obj.id); } } for (const key of Object.keys(matchesDailyCache)) { const obj: ITSMatchDailyCache = JSON.parse(matchesDailyCache[key]); if (obj.match_time < time && !matchesRealTimeSharing.get(obj.id)){ matchIdsDailyRemove.add(key); matchesDailySharing.delete(obj.id); } } this.pushMatchEndToQueue(Array.from(matchIdsDailyRemove.values())); for(const [key, values] of matchesIncidentCornerInCache){ const realTimeMatch = matchesRealTimeSharing.get(key); if (!realTimeMatch){ matchIdsIncidentRemove.push(key); matchesIncidentCornerSharing.delete(key); } } this.redisService.hmdel(RedisKey.MatchEndedToday, matchEndedIdsRemove); this.redisService.hmdel(RedisKey.MatchDaily, Array.from(matchIdsDailyRemove.values())); this.redisService.hmdel(RedisKey.MatchesIncidentCorner, matchIdsIncidentRemove); this.redisService.del(RedisKey.FootballExport); pipeline.del(today_); pipeline.del(yesterday); pipeline.del(`${today_}_mapping`); pipeline.del(`${yesterday}_mapping`); pipeline.del(`${RedisKey.OddInplay}`); pipeline.exec(); }
Editor is loading...
Leave a Comment