本文整理了Java中redis.clients.jedis.Jedis.zrangeByScore()
方法的一些代码示例,展示了Jedis.zrangeByScore()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.zrangeByScore()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:zrangeByScore
[英]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.zrangeByScore(key, min, max);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max, offset, count);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max, offset, count);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max, offset, count);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> execute(Jedis connection) {
return connection.zrangeByScore(key, min, max, offset, count);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(keyByte, min, max);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(keyByte, min, max, offset, count);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> zrangeByScore(String key, double min, double max) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> zrangeByScore(String key, String min, String max) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<String> zrangeByScore(String key, String min, String max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count);
}
代码示例来源:origin: sohutv/cachecloud
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(keyByte,
SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
public Set<byte[]> execute(Jedis connection) {
return connection.zrangeByScore(keyByte, SafeEncoder.encode(min), SafeEncoder.encode(max));
}
}.runBinary(keyByte);
内容来源于网络,如有侵权,请联系作者删除!