Skip to content

Commit

Permalink
feat: 更新活跃信息缓存时间
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed Aug 20, 2023
1 parent c6a0a11 commit 95e4eb0
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ public void addActivityScore(Long userId, ActivityScoreBo activityScore) {
if (score > 0) {
// 记录加分记录
RedisClient.hSet(userActionKey, field, score);
RedisClient.expire(userActionKey, DateUtil.ONE_DAY_SECONDS);
// 个人用户的操作记录,保存一个月的有效期,方便用户查询自己最近31天的活跃情况
RedisClient.expire(userActionKey, 31 * DateUtil.ONE_DAY_SECONDS);

// 更新当天和当月的活跃度排行榜
Double newAns = RedisClient.zIncrBy(todayRankKey, String.valueOf(userId), score);
log.info("新增评分! key#field = {}#{}, add = {}, newScore = {}", todayRankKey, userId, score, newAns);
RedisClient.zIncrBy(monthRankKey, String.valueOf(userId), score);
if (newAns <= score) {
RedisClient.expire(todayRankKey, DateUtil.ONE_DAY_SECONDS);
RedisClient.expire(monthRankKey, DateUtil.ONE_MONTH_SECONDS);
// 日活跃榜单,保存31天;月活跃榜单,保存1年
RedisClient.expire(todayRankKey, 31 * DateUtil.ONE_DAY_SECONDS);
RedisClient.expire(monthRankKey, 12 * DateUtil.ONE_MONTH_SECONDS);
}
}
} else if (ans > 0) {
Expand Down

0 comments on commit 95e4eb0

Please sign in to comment.