本文整理了Java中redis.clients.jedis.Jedis.srandmember()
方法的一些代码示例,展示了Jedis.srandmember()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.srandmember()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:srandmember
[英]Return a random element from a Set, without removing the element. If the Set is empty or the key does not exist, a nil object is returned.
The SPOP command does a similar work but the returned element is popped (removed) from the Set.
Time complexity O(1)
[中]从集合中返回一个随机元素,而不删除该元素。如果集合为空或键不存在,则返回nil对象。
SPOP命令执行类似的工作,但返回的元素从集合中弹出(删除)。
时间复杂度O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public String execute(Jedis connection) {
return connection.srandmember(key);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public List<String> execute(Jedis connection) {
return connection.srandmember(key, count);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public List<byte[]> execute(Jedis connection) {
return connection.srandmember(key, count);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
public byte[] execute(Jedis connection) {
return connection.srandmember(keyByte);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
@Override
public byte[] execute(Jedis connection) {
return connection.srandmember(key);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public List<String> srandmember(String key, int count) {
Jedis j = getShard(key);
return j.srandmember(key, count);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public List srandmember(byte[] key, int count) {
Jedis j = getShard(key);
return j.srandmember(key, count);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public String srandmember(String key) {
Jedis j = getShard(key);
return j.srandmember(key);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public byte[] srandmember(byte[] key) {
Jedis j = getShard(key);
return j.srandmember(key);
}
代码示例来源:origin: Netflix/conductor
@Override
public String srandmember(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.srandmember(key);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: Netflix/conductor
@Override
public List<String> srandmember(String key, int count) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.srandmember(key, count);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 返回集合中的一个随机元素。
*/
@SuppressWarnings("unchecked")
public <T> T srandmember(Object key) {
Jedis jedis = getJedis();
try {
return (T)valueFromBytes(jedis.srandmember(keyToBytes(key)));
}
finally {close(jedis);}
}
代码示例来源:origin: jfinal/jfinal
/**
* 返回集合中的 count 个随机元素。
* 从 Redis 2.6 版本开始, SRANDMEMBER 命令接受可选的 count 参数:
* 如果 count 为正数,且小于集合基数,那么命令返回一个包含 count 个元素的数组,数组中的元素各不相同。
* 如果 count 大于等于集合基数,那么返回整个集合。
* 如果 count 为负数,那么命令返回一个数组,数组中的元素可能会重复出现多次,而数组的长度为 count 的绝对值。
* 该操作和 SPOP 相似,但 SPOP 将随机元素从集合中移除并返回,而 SRANDMEMBER 则仅仅返回随机元素,而不对集合进行任何改动。
*/
@SuppressWarnings("rawtypes")
public List srandmember(Object key, int count) {
Jedis jedis = getJedis();
try {
List<byte[]> data = jedis.srandmember(keyToBytes(key), count);
return valueListFromBytesList(data);
}
finally {close(jedis);}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public List<byte[]> sRandMember(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
if (count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().srandmember(key, (int) count)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().srandmember(key, (int) count)));
return null;
}
return connection.getJedis().srandmember(key, (int) count);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public byte[] sRandMember(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().srandmember(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().srandmember(key)));
return null;
}
return connection.getJedis().srandmember(key);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
public String sRandMember(String key){
Jedis jedis = null;
boolean sucess = true;
String ret = null;
try {
jedis = jedisPool.getResource();
ret = jedis.srandmember(key);
} catch (Exception e) {
sucess = false;
returnBrokenResource(jedis, "lpop key:"+key, e);
} finally {
if (sucess && jedis != null) {
returnResource(jedis);
}
}
return ret;
}
代码示例来源:origin: jwpttcg66/NettyGameServer
public List<String> sRandMember(String key, int count){
Jedis jedis = null;
boolean sucess = true;
List<String> ret = null;
try {
jedis = jedisPool.getResource();
ret = jedis.srandmember(key, count);
} catch (Exception e) {
sucess = false;
returnBrokenResource(jedis, "sRandMember key:"+key, e);
} finally {
if (sucess && jedis != null) {
returnResource(jedis);
}
}
return ret;
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public List<String> srandmember(String key, int count) {
String command = "srandmember";
return instrumented(command, () -> delegated.srandmember(key, count));
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public List<byte[]> srandmember(byte[] key, int count) {
String command = "srandmember";
return instrumented(command, () -> delegated.srandmember(key, count));
}
代码示例来源:origin: yangfuhai/jboot
/**
* 返回集合中的一个随机元素。
*/
@SuppressWarnings("unchecked")
public <T> T srandmember(Object key) {
Jedis jedis = getJedis();
try {
return (T) valueFromBytes(jedis.srandmember(keyToBytes(key)));
} finally {
returnResource(jedis);
}
}
内容来源于网络,如有侵权,请联系作者删除!