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;
}