redis存储点赞量,要求按照点赞量由多到少排序

功能点需求,设计作品存在点赞量属性,该属性放入redis,现在需要安装点赞量排序,考虑redis的set,即对应ZSetOperations。

/**  * 增加点赞量  *  * @param workId  * @return  * @author qiaolu  * @date 2015-12-19  */          
public Double incrWorkNice(Long workId) {                                                                        ZSetOperations<String,Long> zSetOperations = kvIncrementRedisTemplate.opsForZSet();          
  return zSetOperations.incrementScore(KeyUtils.workNice(),workId,1);                             }
/**  * 减少点赞量  *  * @param workId  * @return  * @author qiaolu  * @date 2015-12-19  */           
public Integer cutWorkNice(Long workId) {
        ZSetOperations<String,Long> zSetOperations = kvIncrementRedisTemplate.opsForZSet();                return zSetOperations.incrementScore(KeyUtils.workNice(),workId,-1).intValue();             }
/**  * 获取作品点赞量  *  * @param workId 作品ID  * @return Integer  * @author qiaolu  * @since 2015-12-19  */                                                                                        public Integer getWorkNice(Long workId) {
    ZSetOperations<String,Long> zSetOperations =   kvIncrementRedisTemplate.opsForZSet();             
return zSetOperations.score(KeyUtils.workNice(),workId).intValue(); }
/**  * count 代表 查出来几个  返回id集合倒叙排  * @param count  * @return Set  *  * @author qiaolu  * @since 2016-1-22  */                                                                             public Set<Long> getOrderByWorkNice(Long count){
    ZSetOperations<String,Long> zSetOperations = kvIncrementRedisTemplate.opsForZSet();           
    Long min = new Long(0);                                                                      return zSetOperations.reverseRange(KeyUtils.workNice(), min, count - 1); }

你可能感兴趣的:(java,redis,排序)