Java 类org.springframework.data.redis.core.ZSetOperations 实例源码

项目:pcc-like    文件:LikeServiceImpl.java   
@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;
    }
}
项目:pcc-like    文件:LikeServiceImpl.java   
@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();
}
项目:pcc-like    文件:LikeServiceImpl.java   
@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);
}
项目:shoucang    文件:HotPostService.java   
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);
    });
}
项目:spring-analytics    文件:RedisFieldValueCounterRepository.java   
protected Map<String, Double> getZSetData(String counterKey) {
    Set<ZSetOperations.TypedTuple<String>> rangeWithScore = this.redisTemplate
            .boundZSetOps(counterKey).rangeWithScores(0, -1);
    Map<String, Double> values = new HashMap<String, Double>(
            rangeWithScore.size());
    for (Iterator<ZSetOperations.TypedTuple<String>> iterator = rangeWithScore.iterator(); iterator
            .hasNext();) {
        ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
        values.put(typedTuple.getValue(), typedTuple.getScore());
    }
    return values;
}
项目:shoucang    文件:HotPostService.java   
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);
    });
}
项目:openyu-commons    文件:RedisBaoSupporter.java   
@Override
public ZSetOperations<K, V> opsForZSet() {
    try {
        return redisTemplate.opsForZSet();
    } catch (Exception ex) {
        throw new RedisBaoException(ex);
    }
}
项目:expper    文件:HotPostService.java   
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);
    });
}
项目:shoucang    文件:PostListService.java   
public List<Post> getHotPostsOfPage(int page, int pageSize) throws PageNotFoundException {
    Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScore(page, pageSize);
    return getHotPostsOfPage(page, idsWithScore);
}
项目:shoucang    文件:PostListService.java   
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);
}
项目:shoucang    文件:PostListService.java   
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);
}
项目:shoucang    文件:HotPostService.java   
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScore(int page, int pageSize) {
    return hotPosts.reverseRangeWithScores(CACHE_HOT_POSTS, page * pageSize, (page + 1) * pageSize - 1);
}
项目:shoucang    文件:HotPostService.java   
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);
}
项目:shoucang    文件:HotPostService.java   
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);
}
项目:redis-admin    文件:MyRedisTemplate.java   
@Override
public ZSetOperations<K, V> opsForZSet() {
    int dbIndex = RedisApplication.redisConnectionDbIndex.get();
    return new DefaultZSetOperations<K, V>(this, dbIndex);
}
项目:shoucang    文件:PostListService.java   
public List<Post> getHotPostsOfPage(int page, int pageSize) throws PageNotFoundException {
    Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScore(page, pageSize);
    return getHotPostsOfPage(page, idsWithScore);
}
项目:shoucang    文件:PostListService.java   
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);
}
项目:shoucang    文件:PostListService.java   
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);
}
项目:shoucang    文件:HotPostService.java   
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScore(int page, int pageSize) {
    return hotPosts.reverseRangeWithScores(CACHE_HOT_POSTS, page * pageSize, (page + 1) * pageSize - 1);
}
项目:shoucang    文件:HotPostService.java   
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);
}
项目:shoucang    文件:HotPostService.java   
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);
}
项目:springboot-quick-build    文件:RedisServiceImpl.java   
public ZSetOperations<String, String> zSetOps() {
    return redisTemplate.opsForZSet();
}
项目:Camel    文件:RedisSortedSetTest.java   
@Before
public void setUp() throws Exception {
    redisTemplate = mock(RedisTemplate.class);
    zSetOperations = mock(ZSetOperations.class);
    super.setUp();
}
项目:expper    文件:PostListService.java   
public List<Post> getHotPostsOfPage(int page, int pageSize) throws PageNotFoundException {
    Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScore(page, pageSize);
    return getHotPostsOfPage(page, idsWithScore);
}
项目:expper    文件:PostListService.java   
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);
}
项目:expper    文件:PostListService.java   
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);
}
项目:expper    文件:HotPostService.java   
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScore(int page, int pageSize) {
    return hotPosts.reverseRangeWithScores(CACHE_HOT_POSTS, page * pageSize, (page + 1) * pageSize - 1);
}
项目:expper    文件:HotPostService.java   
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);
}
项目:expper    文件:HotPostService.java   
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);
}
项目:phone    文件:RedisClientSupport.java   
public ZSetOperations<String, Object> opsForZSet(){
        return redisTemplate.opsForZSet();
    }
项目:openyu-commons    文件:RedisBao.java   
ZSetOperations<K, V> opsForZSet();