本文整理了Java中redis.clients.jedis.Jedis.zrange()
方法的一些代码示例,展示了Jedis.zrange()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.zrange()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:zrange
[英]Return the all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).
The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).
Using the optional #zrangeByScore(String,double,double,int,int) it's possible to get only a range of the matching elements in an SQL-alike way. Note that if offset is large the commands needs to traverse the list for offset elements and this adds up to the O(M) figure.
The #zcount(String,double,double) command is similar to #zrangeByScore(String,double,double) but instead of returning the actual elements in the specified interval, it just returns the number of matching elements.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".
Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:
ZRANGEBYSCORE zset (1.3 5
Will return all the values with score > 1.3 and <= 5, while for instance:
ZRANGEBYSCORE zset (5 (10
Will return all the values with score > 5 and < 10 (5 and 10 excluded).
Time complexity:
O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements returned by the command, so if M is constant (for instance you always ask for the first ten elements with LIMIT) you can consider it O(log(N))
[中]返回排序集中得分介于min和max之间的所有元素(包括得分等于min或max的元素)。
具有相同分数的元素按ASCII字符串的字典顺序返回(这源自Redis排序集的属性,不涉及进一步的计算)。
使用可选的#zrangeByScore(String、double、double、int、int)可以以类似SQL的方式仅获取一系列匹配元素。请注意,如果偏移量较大,则命令需要遍历偏移元素的列表,这将相加为O(M)图。
#zcount(String,double,double)命令类似于#zrangeByScore(String,double,double),但它只返回匹配元素的数量,而不是返回指定间隔内的实际元素。
互斥区间与无穷大
最小值和最大值可以是-inf和+inf,这样您就不需要知道最大或最小的元素是什么,例如,要获取“达到给定值”的元素。
此外,虽然间隔是默认关闭的(包括),但可以指定以“(”字符作为分数前缀的打开间隔,例如:
ZRANGEBYSCORE zset(1.3 5
将返回得分>1.3且<=5的所有值,例如:
ZRANGEBYSCORE zset(5(10
将返回分数大于5且小于10的所有值(不包括5和10)。
时间复杂性:
O(log(n))+o(m),n是排序集合中元素的数目,m是命令返回的元素数,因此如果m是常数(例如,总是要求具有限制的前十个元素),则可以考虑O(log(n))。
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> execute(Jedis connection) {
return connection.zrange(key, start, end);
}
}.run(key);
代码示例来源:origin: Impetus/Kundera
rowKeys = ((Jedis) connection).zrange(destStore, 0, -1);
((Jedis) connection).del(destStore);
rowKeys = new HashSet<String>(((Jedis) connection).zrange(
getHashKey(entityMetadata.getTableName(),
((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName()), 0, -1));
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zrange(key, start, end);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
public Set<byte[]> execute(Jedis connection) {
return connection.zrange(keyByte, start, end);
}
}.runBinary(keyByte);
代码示例来源:origin: yu199195/Raincat
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: yu199195/hmily
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> zrange(String key, long start, long end) {
Jedis j = getShard(key);
return j.zrange(key, start, end);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> zrange(byte[] key, long start, long end) {
Jedis j = getShard(key);
return j.zrange(key, start, end);
}
代码示例来源:origin: yu199195/hmily
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Set<String> zrange(final String key, final long start, final long end) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.zrange(key, start, end);
}
}
代码示例来源:origin: Netflix/conductor
@Override
public Set<String> zrange(String key, long start, long end) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.zrange(key, start, end);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 返回有序集 key 中,指定区间内的成员。
* 其中成员的位置按 score 值递增(从小到大)来排序。
* 具有相同 score 值的成员按字典序(lexicographical order )来排列。
* 如果你需要成员按 score 值递减(从大到小)来排列,请使用 ZREVRANGE 命令。
*/
@SuppressWarnings("rawtypes")
public Set zrange(Object key, long start, long end) {
Jedis jedis = getJedis();
try {
Set<byte[]> data = jedis.zrange(keyToBytes(key), start, end);
Set<Object> result = new LinkedHashSet<Object>(); // 有序集合必须 LinkedHashSet
valueSetFromBytesSet(data, result);
return result;
}
finally {close(jedis);}
}
代码示例来源:origin: prestodb/presto
private boolean fetchKeys()
{
try (Jedis jedis = jedisPool.getResource()) {
switch (split.getKeyDataType()) {
case STRING: {
String cursor = SCAN_POINTER_START;
if (redisCursor != null) {
cursor = redisCursor.getStringCursor();
}
log.debug("Scanning new Redis keys from cursor %s . %d values read so far", cursor, totalValues);
redisCursor = jedis.scan(cursor, scanParms);
List<String> keys = redisCursor.getResult();
keysIterator = keys.iterator();
}
break;
case ZSET:
Set<String> keys = jedis.zrange(split.getKeyName(), split.getStart(), split.getEnd());
keysIterator = keys.iterator();
break;
default:
log.debug("Redis type of key %s is unsupported", split.getKeyDataFormat());
return false;
}
}
return true;
}
代码示例来源:origin: Dreampie/Resty
Set<byte[]> rawKeys = jedis.zrange(groupRawKeys, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - 1);
finished = rawKeys.size() < PAGE_SIZE;
offset++;
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Set<byte[]> zRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().zrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().zrange(key, start, end)));
return null;
}
return connection.getJedis().zrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: sanluan/PublicCMS
@Override
public List<V> clear() {
List<V> list = new ArrayList<>();
Jedis jedis = jedisPool.getResource();
Set<byte[]> keyList = jedis.zrange(byteRegion, 0, -1);
if (0 < jedis.del(byteRegion)) {
for (byte[] byteKey : keyList) {
byte[] key = getKey(keySerializer.deserialize(byteKey));
list.add(valueSerializer.deserialize(jedis.get(key)));
jedis.del(key);
}
}
jedis.close();
return list;
}
代码示例来源:origin: sanluan/PublicCMS
@Override
public List<V> clear() {
List<V> list = new ArrayList<>();
Jedis jedis = jedisPool.getResource();
Set<byte[]> keyList = jedis.zrange(byteRegion, 0, -1);
if (0 < jedis.del(byteRegion)) {
for (byte[] byteKey : keyList) {
byte[] key = getKey(keySerializer.deserialize(byteKey));
list.add(valueSerializer.deserialize(jedis.get(key)));
jedis.del(key);
}
}
jedis.close();
return list;
}
代码示例来源:origin: gresrun/jesque
protected KeyInfo handleZSet(final Jedis jedis) {
final KeyInfo keyInfo = new KeyInfo(this.key, KeyType.ZSET);
keyInfo.setSize(jedis.zcard(this.key));
if (this.doArrayValue) {
keyInfo.setArrayValue(new ArrayList<String>(
jedis.zrange(this.key, this.offset, this.offset + this.count)));
}
return keyInfo;
}
内容来源于网络,如有侵权,请联系作者删除!