Merge branch 'master' of https://github.com/lmar/jedis into lmar-master

Conflicts:
	src/main/java/redis/clients/jedis/Pipeline.java
	src/main/java/redis/clients/jedis/PipelineBlock.java
This commit is contained in:
Jonathan Leibiusky
2011-04-06 21:52:48 -03:00
12 changed files with 406 additions and 7 deletions

View File

@@ -495,23 +495,41 @@ public class BinaryClient extends Connection {
final double max) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max));
}
public void zrevrangeByScore(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min));
}
public void zrangeByScore(final byte[] key, final byte[] min,
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) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
LIMIT.raw, toByteArray(offset), toByteArray(count));
}
public void zrevrangeByScore(final byte[] key, final double max,
final double min, final int offset, int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
LIMIT.raw, toByteArray(offset), toByteArray(count));
}
public void zrangeByScoreWithScores(final byte[] key, final double min,
final double max) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
WITHSCORES.raw);
}
public void zrangeByScoreWithScores(final byte[] key, final double min,
final double max, final int offset, final int count) {
@@ -519,6 +537,12 @@ public class BinaryClient extends Connection {
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min, final int offset, final int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}
public void zremrangeByRank(final byte[] key, final int start, final int end) {
sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end));
@@ -670,4 +694,4 @@ public class BinaryClient extends Connection {
public void getrange(byte[] key, long startOffset, long endOffset) {
sendCommand(GETRANGE, key, toByteArray(startOffset), toByteArray(endOffset));
}
}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -435,6 +435,33 @@ public class Client extends BinaryClient implements Commands {
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,
count);
}
public void zremrangeByRank(final String key, final int start, final int end) {
zremrangeByRank(SafeEncoder.encode(key), start, end);
}
@@ -560,4 +587,4 @@ public class Client extends BinaryClient implements Commands {
}
subscribe(cs);
}
}
}

View File

@@ -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,

View File

@@ -2270,6 +2270,44 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return set;
}
public Set<String> zrevrangeByScore(final String key, final double max,
final double min) {
checkIsInMulti();
client.zrevrangeByScore(key, max, min);
return new LinkedHashSet<String>(client.getMultiBulkReply());
}
public Set<String> zrevrangeByScore(final String key, final String max,
final String min) {
checkIsInMulti();
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) {
checkIsInMulti();
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) {
checkIsInMulti();
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) {
checkIsInMulti();
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
@@ -2582,4 +2620,4 @@ public class Jedis extends BinaryJedis implements JedisCommands {
client.getrange(key, startOffset, endOffset);
return client.getBulkReply();
}
}
}

View File

@@ -136,14 +136,20 @@ public interface JedisCommands {
Long zcount(String key, double min, double max);
Set<String> zrangeByScore(String key, double min, double max);
Set<String> zrevrangeByScore(String key, double max, double min);
Set<String> zrangeByScore(String key, double min, double max, int offset,
int count);
Set<String> zrevrangeByScore(String key, double max, double min, int offset,
int count);
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max);
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min);
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max,
int offset, int count);
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min,
int offset, int count);
Long zremrangeByRank(String key, int start, int end);

View File

@@ -922,6 +922,66 @@ public class Pipeline extends Queable {
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<String>> zrevrangeByScore(String key, double max,
double min) {
client.zrevrangeByScore(key, max, min);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(byte[] key, double max,
double min) {
client.zrevrangeByScore(key, max, min);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(String key, String max,
String min) {
client.zrevrangeByScore(key, max, min);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(byte[] key, byte[] max,
byte[] min) {
client.zrevrangeByScore(key, max, min);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(String key, double max,
double min, int offset, int count) {
client.zrevrangeByScore(key, max, min, offset, count);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(byte[] key, double max,
double min, int offset, int count) {
client.zrevrangeByScore(key, max, min, offset, count);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
double max, double min) {
client.zrevrangeByScoreWithScores(key, max, min);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
double max, double min) {
client.zrevrangeByScoreWithScores(key, max, min);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
double max, double min, int offset, int count) {
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
double max, double min, int offset, int count) {
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrangeWithScores(String key, int start, int end) {
client.zrangeWithScores(key, start, end);
return getResponse(BuilderFactory.TUPLE_ZSET);
@@ -1095,4 +1155,4 @@ public class Pipeline extends Queable {
public void multi() {
client.multi();
}
}
}

View File

@@ -135,7 +135,7 @@ public final class Protocol {
}
public static enum Command {
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE;
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE;
public final byte[] raw;
@@ -153,4 +153,4 @@ public final class Protocol {
}
}
}
}

View File

@@ -353,23 +353,41 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
public Set<String> zrevrangeByScore(String key, double max, double min) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min);
}
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);
}
public Set<String> zrevrangeByScore(String key, double max, double min,
int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count);
}
public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max);
}
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min);
}
public Set<Tuple> zrangeByScoreWithScores(String key, double min,
double max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max, offset, count);
}
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max,
double min, int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
}
public Long zremrangeByRank(String key, int start, int end) {
Jedis j = getShard(key);
@@ -386,4 +404,4 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
Jedis j = getShard(key);
return j.linsert(key, where, pivot, value);
}
}
}

View File

@@ -449,6 +449,83 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
}
@Test
public void zrevrangebyscore() {
jedis.zadd("foo", 1.0d, "a");
jedis.zadd("foo", 2.0d, "b");
jedis.zadd("foo", 3.0d, "c");
jedis.zadd("foo", 4.0d, "d");
jedis.zadd("foo", 5.0d, "e");
Set<String> range = jedis.zrevrangeByScore("foo", 3d, Double.NEGATIVE_INFINITY, 0, 1);
Set<String> expected = new LinkedHashSet<String>();
expected.add("c");
assertEquals(expected, range);
range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, 0, 2);
expected = new LinkedHashSet<String>();
expected.add("c");
expected.add("b");
assertEquals(expected, range);
range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, 1, 1);
expected = new LinkedHashSet<String>();
expected.add("b");
assertEquals(expected, range);
range = jedis.zrevrangeByScore("foo", 4d, 2d);
expected = new LinkedHashSet<String>();
expected.add("d");
expected.add("c");
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
public void zrangebyscoreWithScores() {
jedis.zadd("foo", 1d, "a");
@@ -509,6 +586,70 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
}
@Test
public void zrevrangebyscoreWithScores() {
jedis.zadd("foo", 1.0d, "a");
jedis.zadd("foo", 2.0d, "b");
jedis.zadd("foo", 3.0d, "c");
jedis.zadd("foo", 4.0d, "d");
jedis.zadd("foo", 5.0d, "e");
Set<Tuple> range = jedis.zrevrangeByScoreWithScores("foo", 3d, Double.NEGATIVE_INFINITY, 0, 1);
Set<Tuple> expected = new LinkedHashSet<Tuple>();
expected.add(new Tuple("c", 3.0d));
assertEquals(expected, range);
range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, Double.NEGATIVE_INFINITY, 0, 2);
expected = new LinkedHashSet<Tuple>();
expected.add(new Tuple("c", 3.0d));
expected.add(new Tuple("b", 2.0d));
assertEquals(expected, range);
range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, Double.NEGATIVE_INFINITY, 1, 1);
expected = new LinkedHashSet<Tuple>();
expected.add(new Tuple("b", 2.0d));
assertEquals(expected, range);
range = jedis.zrevrangeByScoreWithScores("foo", 4d, 2d);
expected = new LinkedHashSet<Tuple>();
expected.add(new Tuple("d", 4.0d));
expected.add(new Tuple("c", 3.0d));
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
public void zremrangeByRank() {
jedis.zadd("foo", 1d, "a");