Binary versions of ZREVRANGEBYSCORE methods, some code cleanup
This commit is contained in:
@@ -486,6 +486,10 @@ public class BinaryClient extends Connection {
|
||||
final byte[] max) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min, max);
|
||||
}
|
||||
public void zrevrangeByScore(final byte[] key, final byte[] max,
|
||||
final byte[] min) {
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max, min);
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final double min,
|
||||
final double max, final int offset, int count) {
|
||||
|
||||
@@ -2326,6 +2326,44 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
|
||||
final double min) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
|
||||
final byte[] min) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
|
||||
final double max, final double min) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
|
||||
final double max, final double min, final int offset,
|
||||
final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all elements in the sorted set at key with rank between start and
|
||||
* end. Start and end are 0-based with rank 0 being the element with the
|
||||
|
||||
@@ -139,6 +139,16 @@ public interface BinaryJedisCommands {
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset,
|
||||
int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Long zremrangeByRank(byte[] key, int start, int end);
|
||||
|
||||
Long zremrangeByScore(byte[] key, double start, double end);
|
||||
|
||||
@@ -357,6 +357,28 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Long zremrangeByRank(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByRank(key, start, end);
|
||||
|
||||
@@ -412,10 +412,6 @@ public class Client extends BinaryClient implements Commands {
|
||||
final double max) {
|
||||
zrangeByScore(SafeEncoder.encode(key), min, max);
|
||||
}
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min) {
|
||||
zrevrangeByScore(SafeEncoder.encode(key), max, min);
|
||||
}
|
||||
|
||||
public void zrangeByScore(final String key, final String min,
|
||||
final String max) {
|
||||
@@ -427,25 +423,39 @@ public class Client extends BinaryClient implements Commands {
|
||||
final double max, final int offset, int count) {
|
||||
zrangeByScore(SafeEncoder.encode(key), min, max, offset, count);
|
||||
}
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, int count) {
|
||||
zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final double min,
|
||||
final double max) {
|
||||
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max);
|
||||
}
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min) {
|
||||
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min);
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final double min,
|
||||
final double max, final int offset, final int count) {
|
||||
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset,
|
||||
count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min) {
|
||||
zrevrangeByScore(SafeEncoder.encode(key), max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final String key, final String max,
|
||||
final String min) {
|
||||
zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max),
|
||||
SafeEncoder.encode(min));
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, int count) {
|
||||
zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min) {
|
||||
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min, offset,
|
||||
|
||||
@@ -197,6 +197,21 @@ public interface Commands {
|
||||
public void zrangeByScoreWithScores(final String key, final double min,
|
||||
final double max, final int offset, final int count);
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min);
|
||||
|
||||
public void zrevrangeByScore(final String key, final String max,
|
||||
final String min);
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, int count);
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min);
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min, final int offset, final int count);
|
||||
|
||||
public void zremrangeByRank(final String key, final int start, final int end);
|
||||
|
||||
public void zremrangeByScore(final String key, final double start,
|
||||
|
||||
@@ -2085,12 +2085,6 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
client.zrangeByScore(key, min, max);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
public Set<String> zrevrangeByScore(final String key, final double max,
|
||||
final double min) {
|
||||
runChecks();
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<String> zrangeByScore(final String key, final String min,
|
||||
final String max) {
|
||||
@@ -2161,12 +2155,6 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
client.zrangeByScore(key, min, max, offset, count);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
public Set<String> zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
runChecks();
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the all the elements in the sorted set at key with a score between
|
||||
@@ -2231,13 +2219,6 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final String key,
|
||||
final double max, final double min) {
|
||||
runChecks();
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the all the elements in the sorted set at key with a score between
|
||||
@@ -2303,14 +2284,6 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final String key,
|
||||
final double max, final double min, final int offset,
|
||||
final int count) {
|
||||
runChecks();
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
private Set<Tuple> getTupledSet() {
|
||||
runChecks();
|
||||
@@ -2325,6 +2298,44 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(final String key, final double max,
|
||||
final double min) {
|
||||
runChecks();
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(final String key, final String max,
|
||||
final String min) {
|
||||
runChecks();
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
runChecks();
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final String key,
|
||||
final double max, final double min) {
|
||||
runChecks();
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final String key,
|
||||
final double max, final double min, final int offset,
|
||||
final int count) {
|
||||
runChecks();
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all elements in the sorted set at key with rank between start and
|
||||
* end. Start and end are 0-based with rank 0 being the element with the
|
||||
|
||||
@@ -722,6 +722,51 @@ public class Pipeline implements Commands {
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
//--
|
||||
public void zrevrangeByScore(String key, double max, double min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(byte[] key, double max, double min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(String key, String max, String min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(byte[] key, byte[] max, byte[] min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(String key, double max, double min, int offset,
|
||||
int count) {
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(byte[] key, double max, double min, int offset,
|
||||
int count) {
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(String key, double max, double min) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(byte[] key, double max, double min) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(String key, double max, double min,
|
||||
int offset, int count) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
||||
int offset, int count) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrangeWithScores(String key, int start, int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
@@ -374,6 +374,28 @@ public abstract class PipelineBlock implements Commands {
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(String key, double max, double min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(String key, String max, String min) {
|
||||
client.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(String key, double max, double min, int offset,
|
||||
int count) {
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(String key, double max, double min) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(String key, double max, double min,
|
||||
int offset, int count) {
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public void zrangeWithScores(String key, int start, int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
@@ -483,6 +483,47 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
expected.add("b");
|
||||
|
||||
assertEquals(expected, range);
|
||||
|
||||
range = jedis.zrevrangeByScore("foo", "+inf", "(4");
|
||||
expected = new LinkedHashSet<String>();
|
||||
expected.add("e");
|
||||
|
||||
assertEquals(expected, range);
|
||||
|
||||
// Binary
|
||||
jedis.zadd(bfoo, 1d, ba);
|
||||
jedis.zadd(bfoo, 10d, bb);
|
||||
jedis.zadd(bfoo, 0.1d, bc);
|
||||
jedis.zadd(bfoo, 2d, ba);
|
||||
|
||||
Set<byte[]> brange = jedis.zrevrangeByScore(bfoo, 2d, 0d);
|
||||
|
||||
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bc);
|
||||
bexpected.add(ba);
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 0, 1);
|
||||
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(ba);
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
Set<byte[]> brange2 = jedis.zrevrangeByScore(bfoo, SafeEncoder
|
||||
.encode("+inf"), SafeEncoder.encode("(2"));
|
||||
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
|
||||
assertEquals(bexpected, brange2);
|
||||
|
||||
brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 1, 1);
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bc);
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -579,6 +620,34 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
expected.add(new Tuple("b", 2.0d));
|
||||
|
||||
assertEquals(expected, range);
|
||||
|
||||
// Binary
|
||||
jedis.zadd(bfoo, 1d, ba);
|
||||
jedis.zadd(bfoo, 10d, bb);
|
||||
jedis.zadd(bfoo, 0.1d, bc);
|
||||
jedis.zadd(bfoo, 2d, ba);
|
||||
|
||||
Set<Tuple> brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d);
|
||||
|
||||
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(bc, 0.1d));
|
||||
bexpected.add(new Tuple(ba, 2d));
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 0, 1);
|
||||
|
||||
bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(ba, 2d));
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 1, 1);
|
||||
|
||||
bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(bc, 0.1d));
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user