This commit is contained in:
张良(004796)
2024-02-04 18:52:07 +08:00
parent 684216368c
commit 9e29c5f321
22 changed files with 700 additions and 11 deletions

View File

@@ -18,20 +18,35 @@ public class OnlineUserTodayCache {
@Autowired
private RedissonClient redissonClient;
private String getKey(LocalDateTime dateTime){
private String getKey(LocalDate dateTime){
String today = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
return String.format(CacheConstants.ONLINE_TODAY_TOKEN_KEY,today);
}
public boolean addOnlineUserId(Long userId, LocalDateTime dateTime){
public boolean addOnlineUserId(Long userId, LocalDate dateTime){
RSet<Long> set = redissonClient.getSet(getKey(dateTime));
boolean res = set.add(userId);
set.expire(Duration.ofDays(1));
set.expire(Duration.ofDays(3));
return res;
}
public Set<Long> getAllOnlineToday(){
RSet<Long> set = redissonClient.getSet(getKey(LocalDateTime.now()));
RSet<Long> set = redissonClient.getSet(getKey(LocalDate.now()));
return set.readAll();
}
public Long getOnlineNum(LocalDate time){
RSet<Long> set = redissonClient.getSet(getKey(time));
return (long) set.size();
}
public Long getOnlineTodayNum(){
RSet<Long> set = redissonClient.getSet(getKey(LocalDate.now()));
return (long) set.size();
}
public Long getOnlineLastNum(){
RSet<Long> set = redissonClient.getSet(getKey(LocalDate.now().plusDays(-1)));
return (long) set.size();
}
}