美文网首页
jedis 3.0.0-SNAPSHOT spop 不可用

jedis 3.0.0-SNAPSHOT spop 不可用

作者: 安心远 | 来源:发表于2017-01-13 11:55 被阅读123次

jedis 3.0.0-SNAPSHOT 版本提供的:

jedis.spop(String key,long count);

不可用,自己实现代码:

public Set<String> spop(RedisDbName redisDbName, String key, long count) {
 Jedis jedis = null;
 try {
       Set<String> set = new HashSet<>();
       jedis = RedisPool.getMasterJedis(redisDbName);
       long scard = jedis.scard(key);
       scard = scard>count?count:scard;
       for (int i=0;i<scard;i++){
             String v = jedis.spop(key);
             if(v!=null) set.add(v);
             else return set;
       }
       return set;
 } catch (Exception ex) {
       logger.error("spop error."+ex.getMessage());
       if (null != jedis) jedis.close();
       } finally {
         if (null != jedis) jedis.close();
     }
     return null;
}

相关文章

网友评论

      本文标题:jedis 3.0.0-SNAPSHOT spop 不可用

      本文链接:https://www.haomeiwen.com/subject/exqsbttx.html