org.springframework.data.redis.core.ZSetOperations Java Examples
The following examples show how to use
org.springframework.data.redis.core.ZSetOperations.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChengfengReadyListener.java From ChengFeng1.5 with MIT License | 6 votes |
@Override public void onApplicationEvent(ApplicationReadyEvent event) { log.info("》》》》》》》》》》城风已就绪《《《《《《《《《《"); CommunityNoticeMapper communityNoticeMapper = event.getApplicationContext().getBean(CommunityNoticeMapper.class); ProperNoticeMapper properNoticeMapper = event.getApplicationContext().getBean(ProperNoticeMapper.class); StringRedisTemplate stringRedisTemplate=event.getApplicationContext().getBean(StringRedisTemplate.class); List<CommunityNotice> communityNotices = communityNoticeMapper.selectAllCommunities(); List<ProperNotice> properNotices = properNoticeMapper.selectAllPropers(); ZSetOperations<String, String> zset = stringRedisTemplate.opsForZSet(); HashOperations<String, Object, Object> hash = stringRedisTemplate.opsForHash(); communityNotices.parallelStream() .forEach(communityNotice ->{ zset.add(RedisConstant.COMMUNITY_NOTICE_ORDER+communityNotice.getCommunityId(),RedisConstant.COMMUNITY_NOTICE_PREFIX+communityNotice.getId(), new DateTime(communityNotice.getShowtime()).getMillis()); hash.put(RedisConstant.COMMUNITY_NOTICES+communityNotice.getCommunityId(),RedisConstant.COMMUNITY_NOTICE_PREFIX+communityNotice.getId(), JsonSerializableUtil.obj2String(communityNotice)); }); properNotices.parallelStream() .forEach(properNotice -> { zset.add(RedisConstant.PROPER_NOTICE_ORDER+properNotice.getUserId(),RedisConstant.PROPER_NOTICE_PREFIX+properNotice.getId(), new DateTime(properNotice.getShowtime()).getMillis()); hash.put(RedisConstant.PROPER_NOTICES+properNotice.getUserId(),RedisConstant.PROPER_NOTICE_PREFIX+properNotice.getId(), JsonSerializableUtil.obj2String(properNotice)); }); }
Example #2
Source File: RedisDelayBucket.java From Milkomeda with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Override public DelayJob poll(Integer index) { String name = bucketNames.get(index); BoundZSetOperations<String, String> bucket = getBucket(name); // 升序查第一个(最上面的是延迟/TTR过期的) Set<ZSetOperations.TypedTuple<String>> set = bucket.rangeWithScores(0, 1); if (CollectionUtils.isEmpty(set)) { return null; } ZSetOperations.TypedTuple<String> typedTuple = set.toArray(new ZSetOperations.TypedTuple[]{})[0]; if (typedTuple.getValue() == null) { return null; } return DelayJob.compatibleDecode(typedTuple.getValue(), typedTuple.getScore()); }
Example #3
Source File: JobOperationServiceImpl.java From mykit-delay with Apache License 2.0 | 6 votes |
@Override public List<String> getBucketTopJobs(String bucketName, int size) { double to = Long.valueOf(System.currentTimeMillis() + BucketTask.TIME_OUT).doubleValue(); Set<ZSetOperations.TypedTuple<String>> sets = redisSupport.zrangeByScoreWithScores(bucketName, 0, to, 0, size); List<String> lsts = Lists.newArrayList(); if (sets != null && sets.size() > 0) { Iterator<ZSetOperations.TypedTuple<String>> it = sets.iterator(); while (it.hasNext()) { ZSetOperations.TypedTuple<String> curr = it.next(); if (curr.getScore() <= System.currentTimeMillis()) { lsts.add(curr.getValue()); } else { break; } } // String jobMsgId = Objects.toString(sets.toArray()[0]); return lsts; } return null; }
Example #4
Source File: LikeServiceImpl.java From pcc-like with Apache License 2.0 | 6 votes |
@Override public List<Long> likeUserIdsWithFriendsFirst(int start, int pageCount, Long feedId, Long uid) { if (feedId == null) { return Collections.emptyList(); } ZSetOperations<String, String> feedLikes = this.template.opsForZSet(); // 求交集,得到好友关系 feedLikes.intersectAndStore(KEY_FEED_LIKE + feedId, UserServiceImpl.KEY_USER_FRIENDS + uid, KEY_FEED_LIKE_FRIENDS + feedId); Set<String> friends = feedLikes.range(KEY_FEED_LIKE_FRIENDS + feedId, start, start + pageCount); if (friends.size() > pageCount) { return transfer(friends); } else { // TODO // 剩下的,全部遍历,然后检查是否是好友,如果是,直接排除。如果不是,增加到列表中; // 由于涉及到分页,需要记录上次操作的index } return Collections.emptyList(); }
Example #5
Source File: LikeServiceImpl.java From pcc-like with Apache License 2.0 | 6 votes |
@Override @Transactional(propagation = Propagation.REQUIRED) public long unlike(Long feedId, Long uid) { if (feedId == null || uid == null) { return -1; } Like like = likeMapper.getLike(feedId, uid); if (like == null) { return -1; } else { int deleteResult = likeMapper.delete(like.getId()); if (deleteResult > 0) { ZSetOperations<String, String> feedLikes = this.template.opsForZSet(); ValueOperations<String, String> feedCount = this.template.opsForValue(); feedLikes.remove(KEY_FEED_LIKE + feedId, Long.toString(uid)); return feedCount.increment(KEY_FEED_LIKE_COUNT + feedId, -1); } return -1; } }
Example #6
Source File: AnswerService.java From spring-microservice-exam with MIT License | 6 votes |
/** * 获取排名数据 * @param recordId recordId * @return List * @author tangyi * @date 2019/12/8 23:36 */ public List<RankInfoDto> getRankInfo(Long recordId) { List<RankInfoDto> rankInfos = new ArrayList<>(); // 查询缓存 Set<ZSetOperations.TypedTuple<String>> typedTuples = redisTemplate.opsForZSet() .reverseRangeByScoreWithScores(AnswerConstant.CACHE_PREFIX_RANK + recordId, 0, Integer.MAX_VALUE); if (typedTuples != null) { // 用户ID列表 Set<Long> userIds = new HashSet<>(); typedTuples.forEach(typedTuple -> { ExaminationRecord record = JsonMapper.getInstance() .fromJson(typedTuple.getValue(), ExaminationRecord.class); if (record != null) { RankInfoDto rankInfo = new RankInfoDto(); rankInfo.setUserId(record.getUserId()); userIds.add(record.getUserId()); rankInfo.setScore(typedTuple.getScore()); rankInfos.add(rankInfo); } }); if (!userIds.isEmpty()) { ResponseBean<List<UserVo>> userResponse = userServiceClient.findUserById(userIds.toArray(new Long[0])); if (ResponseUtil.isSuccess(userResponse)) { rankInfos.forEach(rankInfo -> { userResponse.getData().stream().filter(user -> user.getId().equals(rankInfo.getUserId())) .findFirst().ifPresent(user -> { // 设置考生信息 rankInfo.setName(user.getName()); rankInfo.setAvatarUrl(user.getAvatarUrl()); }); }); } } } return rankInfos; }
Example #7
Source File: JobOperationServiceImpl.java From sdmq with Apache License 2.0 | 6 votes |
@Override public List<String> getBucketTopJobs(String bucketName, int size) { double to = Long.valueOf(System.currentTimeMillis() + BucketTask.TIME_OUT).doubleValue(); Set<ZSetOperations.TypedTuple<String>> sets = redisSupport.zrangeByScoreWithScores(bucketName, 0, to, 0, size); List<String> lsts = Lists.newArrayList(); if (sets != null && sets.size() > 0) { Iterator<ZSetOperations.TypedTuple<String>> it = sets.iterator(); while (it.hasNext()) { ZSetOperations.TypedTuple<String> curr = it.next(); if (curr.getScore() <= System.currentTimeMillis()) { lsts.add(curr.getValue()); } else { break; } } // String jobMsgId = Objects.toString(sets.toArray()[0]); return lsts; } return null; }
Example #8
Source File: RedisDelayBucket.java From Milkomeda with MIT License | 5 votes |
@Override public void add(List<DelayJob> delayJobs) { String bucketName = getCurrentBucketName(); BoundZSetOperations<String, String> bucket = getBucket(bucketName); Set<ZSetOperations.TypedTuple<String>> delayJobSet = delayJobs.stream() .map(delayJob -> new DefaultTypedTuple<>(delayJob.toSimple(), (double) delayJob.getDelayTime())) .collect(Collectors.toSet()); bucket.add(delayJobSet); }
Example #9
Source File: HotPostService.java From expper with GNU General Public License v3.0 | 5 votes |
public void sortByScore(List<Post> posts, Set<ZSetOperations.TypedTuple<Long>> scores) { Map<Long, Double> map = new HashMap<>(); scores.forEach(s -> map.put(s.getValue(), s.getScore())); posts.sort((o1, o2) -> { double diff = map.get(o2.getId()) - map.get(o1.getId()); return diff > 0 ? 1 : (diff < 0 ? -1 : 0); }); }
Example #10
Source File: LikeServiceImpl.java From pcc-like with Apache License 2.0 | 5 votes |
@Override public List<Long> likeUserIds(int start, int pageCount, Long feedId) { if (feedId == null) { return Collections.emptyList(); } ZSetOperations<String, String> feedLikes = this.template.opsForZSet(); Set<String> uids = feedLikes.range(KEY_FEED_LIKE + feedId, start, start + pageCount - 1); return transfer(uids); }
Example #11
Source File: DataRedisContextInitializer.java From summerframework with Apache License 2.0 | 5 votes |
private void createProxyHandlers(RedisTemplate redisTemplate) { createProxyHandler(redisTemplate, ValueOperations.class, "valueOps"); createProxyHandler(redisTemplate, ListOperations.class, "listOps"); createProxyHandler(redisTemplate, SetOperations.class, "setOps"); createProxyHandler(redisTemplate, ZSetOperations.class, "zSetOps"); createProxyHandler(redisTemplate, GeoOperations.class, "geoOps"); createProxyHandler(redisTemplate, HyperLogLogOperations.class, "hllOps"); }
Example #12
Source File: RedisSupport.java From mykit-delay with Apache License 2.0 | 4 votes |
public Set<ZSetOperations.TypedTuple<String>> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { ZSetOperations<String, String> zset = template.opsForZSet(); Set<ZSetOperations.TypedTuple<String>> set = zset.rangeByScoreWithScores(key, min, max, offset, count); return set; }
Example #13
Source File: RedisSupport.java From mykit-delay with Apache License 2.0 | 4 votes |
public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) { ZSetOperations<String, String> zset = template.opsForZSet(); Set<String> datas = zset.rangeByScore(key, min, max, offset, count); return datas; }
Example #14
Source File: HotPostService.java From expper with GNU General Public License v3.0 | 4 votes |
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScoreOfTopic(Long topicId, int page, int pageSize) { return hotPosts.reverseRangeWithScores(CACHE_HOT_TOPIC_POSTS + topicId, page * pageSize, (page + 1) * pageSize - 1); }
Example #15
Source File: HotPostService.java From expper with GNU General Public License v3.0 | 4 votes |
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScoreOfTag(Long tagId, int page, int pageSize) { return hotPosts.reverseRangeWithScores(CACHE_HOT_TAG_POSTS + tagId, page * pageSize, (page + 1) * pageSize - 1); }
Example #16
Source File: HotPostService.java From expper with GNU General Public License v3.0 | 4 votes |
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScore(int page, int pageSize) { return hotPosts.reverseRangeWithScores(CACHE_HOT_POSTS, page * pageSize, (page + 1) * pageSize - 1); }
Example #17
Source File: PostListService.java From expper with GNU General Public License v3.0 | 4 votes |
public List<Post> getHotPostsOfPage(int page, int pageSize, Topic topic) throws PageNotFoundException { Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScoreOfTopic(topic.getId(), page, pageSize); return getHotPostsOfPage(page, idsWithScore); }
Example #18
Source File: PostListService.java From expper with GNU General Public License v3.0 | 4 votes |
public List<Post> getHotPostsOfPage(int page, int pageSize, Tag tag) throws PageNotFoundException { Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScoreOfTag(tag.getId(), page, pageSize); return getHotPostsOfPage(page, idsWithScore); }
Example #19
Source File: PostListService.java From expper with GNU General Public License v3.0 | 4 votes |
public List<Post> getHotPostsOfPage(int page, int pageSize) throws PageNotFoundException { Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScore(page, pageSize); return getHotPostsOfPage(page, idsWithScore); }
Example #20
Source File: MyRedisTemplate.java From redis-admin with Apache License 2.0 | 4 votes |
@Override public ZSetOperations<K, V> opsForZSet() { int dbIndex = RedisApplication.redisConnectionDbIndex.get(); return new DefaultZSetOperations<K, V>(this, dbIndex); }
Example #21
Source File: RedisSupport.java From mykit-delay with Apache License 2.0 | 4 votes |
public boolean zadd(String key, String itemKey, double score) { ZSetOperations<String, String> zset = template.opsForZSet(); return zset.add(key, itemKey, score); }
Example #22
Source File: RedisSupport.java From mykit-delay with Apache License 2.0 | 4 votes |
public Long zrem(String key, String itemKey) { ZSetOperations<String, String> zset = template.opsForZSet(); return zset.remove(key, itemKey); }
Example #23
Source File: RedisSupport.java From sdmq with Apache License 2.0 | 4 votes |
public Long zrem(String key, String itemKey) { ZSetOperations<String, String> zset = template.opsForZSet(); return zset.remove(key, itemKey); }
Example #24
Source File: RedisSupport.java From sdmq with Apache License 2.0 | 4 votes |
public boolean zadd(String key, String itemKey, double score) { ZSetOperations<String, String> zset = template.opsForZSet(); return zset.add(key, itemKey, score); }
Example #25
Source File: RedisSupport.java From sdmq with Apache License 2.0 | 4 votes |
public Set<ZSetOperations.TypedTuple<String>> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { ZSetOperations<String, String> zset = template.opsForZSet(); Set<ZSetOperations.TypedTuple<String>> set = zset.rangeByScoreWithScores(key, min, max, offset, count); return set; }
Example #26
Source File: RedisSupport.java From sdmq with Apache License 2.0 | 4 votes |
public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) { ZSetOperations<String, String> zset = template.opsForZSet(); Set<String> datas = zset.rangeByScore(key, min, max, offset, count); return datas; }
Example #27
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 2 votes |
/** * 实例化 ZSetOperations 对象,可以使用 ZSet 操作 * * @param redisTemplate * @return */ @Bean public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { return redisTemplate.opsForZSet(); }
Example #28
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 2 votes |
/** * 实例化 ZSetOperations 对象,可以使用 ZSet 操作 * * @param redisTemplate * @return */ @Bean public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { return redisTemplate.opsForZSet(); }
Example #29
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 2 votes |
/** * 实例化 ZSetOperations 对象,可以使用 ZSet 操作 * * @param redisTemplate * @return */ @Bean public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { return redisTemplate.opsForZSet(); }
Example #30
Source File: RedisClientSupport.java From phone with Apache License 2.0 | votes |
public ZSetOperations<String, Object> opsForZSet(){ return redisTemplate.opsForZSet(); }