Added support for -inf, +inf and open/closed intervals to zrangebyscore

This commit is contained in:
Jonathan Leibiusky
2010-10-25 14:19:53 -03:00
parent 8692184f5a
commit 7d3fb44639
3 changed files with 636 additions and 623 deletions

View File

@@ -457,6 +457,10 @@ public class Client extends Connection {
.valueOf(max));
}
public void zrangeByScore(String key, String min, String max) {
sendCommand("ZRANGEBYSCORE", key, min, max);
}
public void zrangeByScore(String key, double min, double max, int offset,
int count) {
sendCommand("ZRANGEBYSCORE", key, String.valueOf(min), String

View File

@@ -2081,6 +2081,7 @@ public class Jedis implements JedisCommands {
* @see #zrangeByScore(String, double, double)
* @see #zrangeByScore(String, double, double, int, int)
* @see #zrangeByScoreWithScores(String, double, double)
* @see #zrangeByScoreWithScores(String, String, String)
* @see #zrangeByScoreWithScores(String, double, double, int, int)
* @see #zcount(String, double, double)
*
@@ -2096,6 +2097,12 @@ public class Jedis implements JedisCommands {
return new LinkedHashSet<String>(client.getMultiBulkReply());
}
public Set<String> zrangeByScore(String key, String min, String max) {
checkIsInMulti();
client.zrangeByScore(key, min, max);
return new LinkedHashSet<String>(client.getMultiBulkReply());
}
/**
* 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).

View File

@@ -220,6 +220,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
assertEquals(expected, range);
range = jedis.zrangeByScore("foo", 0d, 2d, 1, 1);
Set<String> range2 = jedis.zrangeByScore("foo", "-inf", "(2");
assertEquals(expected, range2);
expected = new LinkedHashSet<String>();
expected.add("a");