en -> new DefaultTypedTuple<>((String) en.get(“userId”),
(Double) en.get(“score”))).collect(Collectors.toSet());
// 计算排行榜前先将topN桶删除,防止之前进入桶的用户干扰
redisUtil.delAndZaddExec(GameConstant.USER_SCORE_RANKING_TOPN, vals);
return doTopNScoreList(topN);
}
public List<Map<String, Object>> commonScoreList(String bucketValue, Long topN) {
Set<ZSetOperations.TypedTuple> rangeWithScores
= redisUtil.zRevrangeWithScore(bucketValue, 0L, topN - 1);
List<ZSetOperations.TypedTuple> userScoreTuples = new ArrayList<>(rangeWithScores);
return userScoreTuples.stream().map(tuple -> {
String userId = tuple.getValue();
Double score = tuple.getScore();
Map<String,Object> map = new HashMap<>();
map.put(“userId”, userId);
map.put(“score”, score);
return map;
}).collect(Collectors.toList());
}
public List doTopNScoreList(Long topN) {
List userIdList = new ArrayList<>();
Set<ZSetOperations.TypedTuple> rangeWithScores
= redisUtil.zRevrangeWithScore(GameConstant.USER_SCORE_GENERAL_RANKING_TOPN, 0L, topN - 1);
List<ZSetOperations.TypedTuple> userScoreTuples = new ArrayList<>(rangeWithScores);
List collect = userScoreTuples.stream().map(tuple -> {
String userId = tuple.getValue();
Double score = tuple.getScore();
userIdList.add(userId);
return GameRanking.builder()
.userNo(userId)
.leaderboardS