Now methods accepting infinit and exclusions are supported as String and byte[] overloads

This commit is contained in:
ivowiblo
2012-05-03 23:30:44 -04:00
parent 5244d82450
commit 129e358c9d
12 changed files with 448 additions and 89 deletions

View File

@@ -527,18 +527,8 @@ public class BinaryClient extends Connection {
sendCommand(PUNSUBSCRIBE, patterns); sendCommand(PUNSUBSCRIBE, patterns);
} }
public void zcount(final byte[] key, final double min, final double max) { public void zcount(final byte[] key, final byte[] min, final byte[] max) {
sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max)); sendCommand(ZCOUNT, key, min, max);
}
public void zrangeByScore(final byte[] key, final double min,
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, public void zrangeByScore(final byte[] key, final byte[] min,
@@ -551,40 +541,40 @@ public class BinaryClient extends Connection {
sendCommand(ZREVRANGEBYSCORE, key, max, min); sendCommand(ZREVRANGEBYSCORE, key, max, min);
} }
public void zrangeByScore(final byte[] key, final double min, public void zrangeByScore(final byte[] key, final byte[] min,
final double max, final int offset, int count) { final byte[] max, final int offset, int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), sendCommand(ZRANGEBYSCORE, key, min, max,
LIMIT.raw, toByteArray(offset), toByteArray(count)); LIMIT.raw, toByteArray(offset), toByteArray(count));
} }
public void zrevrangeByScore(final byte[] key, final double max, public void zrevrangeByScore(final byte[] key, final byte[] max,
final double min, final int offset, int count) { final byte[] min, final int offset, int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), sendCommand(ZREVRANGEBYSCORE, key, max, min,
LIMIT.raw, toByteArray(offset), toByteArray(count)); LIMIT.raw, toByteArray(offset), toByteArray(count));
} }
public void zrangeByScoreWithScores(final byte[] key, final double min, public void zrangeByScoreWithScores(final byte[] key, final byte[] min,
final double max) { final byte[] max) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), sendCommand(ZRANGEBYSCORE, key, min, max,
WITHSCORES.raw); WITHSCORES.raw);
} }
public void zrevrangeByScoreWithScores(final byte[] key, final double max, public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max,
final double min) { final byte[] min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), sendCommand(ZREVRANGEBYSCORE, key, max, min,
WITHSCORES.raw); WITHSCORES.raw);
} }
public void zrangeByScoreWithScores(final byte[] key, final double min, public void zrangeByScoreWithScores(final byte[] key, final byte[] min,
final double max, final int offset, final int count) { final byte[] max, final int offset, final int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), sendCommand(ZRANGEBYSCORE, key, min, max,
LIMIT.raw, toByteArray(offset), toByteArray(count), LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw); WITHSCORES.raw);
} }
public void zrevrangeByScoreWithScores(final byte[] key, final double max, public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max,
final double min, final int offset, final int count) { final byte[] min, final int offset, final int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), sendCommand(ZREVRANGEBYSCORE, key, max, min,
LIMIT.raw, toByteArray(offset), toByteArray(count), LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw); WITHSCORES.raw);
} }
@@ -593,9 +583,9 @@ public class BinaryClient extends Connection {
sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end));
} }
public void zremrangeByScore(final byte[] key, final double start, public void zremrangeByScore(final byte[] key, final byte[] start,
final double end) { final byte[] end) {
sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end)); sendCommand(ZREMRANGEBYSCORE, key, start, end);
} }
public void zunionstore(final byte[] dstkey, final byte[]... sets) { public void zunionstore(final byte[] dstkey, final byte[]... sets) {

View File

@@ -2064,6 +2064,10 @@ public class BinaryJedis implements BinaryJedisCommands {
} }
public Long zcount(final byte[] key, final double min, final double max) { public Long zcount(final byte[] key, final double min, final double max) {
return zcount(key, toByteArray(min), toByteArray(max));
}
public Long zcount(final byte[] key, final byte[] min, final byte[] max) {
checkIsInMulti(); checkIsInMulti();
client.zcount(key, min, max); client.zcount(key, min, max);
return client.getIntegerReply(); return client.getIntegerReply();
@@ -2127,9 +2131,7 @@ public class BinaryJedis implements BinaryJedisCommands {
*/ */
public Set<byte[]> zrangeByScore(final byte[] key, final double min, public Set<byte[]> zrangeByScore(final byte[] key, final double min,
final double max) { final double max) {
checkIsInMulti(); return zrangeByScore(key, toByteArray(min), toByteArray(max));
client.zrangeByScore(key, min, max);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
} }
public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min, public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
@@ -2197,6 +2199,11 @@ public class BinaryJedis implements BinaryJedisCommands {
*/ */
public Set<byte[]> zrangeByScore(final byte[] key, final double min, public Set<byte[]> zrangeByScore(final byte[] key, final double min,
final double max, final int offset, final int count) { final double max, final int offset, final int count) {
return zrangeByScore(key, toByteArray(min),toByteArray(max),offset, count);
}
public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
final byte[] max, final int offset, final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrangeByScore(key, min, max, offset, count); client.zrangeByScore(key, min, max, offset, count);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply()); return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
@@ -2260,6 +2267,11 @@ public class BinaryJedis implements BinaryJedisCommands {
*/ */
public Set<Tuple> zrangeByScoreWithScores(final byte[] key, public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final double min, final double max) { final double min, final double max) {
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max));
}
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final byte[] min, final byte[] max) {
checkIsInMulti(); checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max); client.zrangeByScoreWithScores(key, min, max);
Set<Tuple> set = getBinaryTupledSet(); Set<Tuple> set = getBinaryTupledSet();
@@ -2325,6 +2337,12 @@ public class BinaryJedis implements BinaryJedisCommands {
public Set<Tuple> zrangeByScoreWithScores(final byte[] key, public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final double min, final double max, final int offset, final double min, final double max, final int offset,
final int count) { final int count) {
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count);
}
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final byte[] min, final byte[] max, final int offset,
final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max, offset, count); client.zrangeByScoreWithScores(key, min, max, offset, count);
Set<Tuple> set = getBinaryTupledSet(); Set<Tuple> set = getBinaryTupledSet();
@@ -2345,9 +2363,7 @@ public class BinaryJedis implements BinaryJedisCommands {
public Set<byte[]> zrevrangeByScore(final byte[] key, final double max, public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
final double min) { final double min) {
checkIsInMulti(); return zrevrangeByScore(key, toByteArray(max), toByteArray(min));
client.zrevrangeByScore(key, max, min);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
} }
public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max, public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
@@ -2359,6 +2375,11 @@ public class BinaryJedis implements BinaryJedisCommands {
public Set<byte[]> zrevrangeByScore(final byte[] key, final double max, public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
final double min, final int offset, final int count) { final double min, final int offset, final int count) {
return zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count);
}
public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
final byte[] min, final int offset, final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeByScore(key, max, min, offset, count); client.zrevrangeByScore(key, max, min, offset, count);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply()); return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
@@ -2366,6 +2387,17 @@ public class BinaryJedis implements BinaryJedisCommands {
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key, public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final double max, final double min) { final double max, final double min) {
return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min));
}
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final double max, final double min, final int offset,
final int count) {
return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count);
}
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final byte[] max, final byte[] min) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min); client.zrevrangeByScoreWithScores(key, max, min);
Set<Tuple> set = getBinaryTupledSet(); Set<Tuple> set = getBinaryTupledSet();
@@ -2373,7 +2405,7 @@ public class BinaryJedis implements BinaryJedisCommands {
} }
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key, public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final double max, final double min, final int offset, final byte[] max, final byte[] min, final int offset,
final int count) { final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min, offset, count); client.zrevrangeByScoreWithScores(key, max, min, offset, count);
@@ -2416,6 +2448,11 @@ public class BinaryJedis implements BinaryJedisCommands {
*/ */
public Long zremrangeByScore(final byte[] key, final double start, public Long zremrangeByScore(final byte[] key, final double start,
final double end) { final double end) {
return zremrangeByScore(key, toByteArray(start), toByteArray(end));
}
public Long zremrangeByScore(final byte[] key, final byte[] start,
final byte[] end) {
checkIsInMulti(); checkIsInMulti();
client.zremrangeByScore(key, start, end); client.zremrangeByScore(key, start, end);
return client.getIntegerReply(); return client.getIntegerReply();

View File

@@ -131,6 +131,8 @@ public interface BinaryJedisCommands {
Long zcount(byte[] key, double min, double max); Long zcount(byte[] key, double min, double max);
Long zcount(byte[] key, byte[] min, byte[] max);
Set<byte[]> zrangeByScore(byte[] key, double min, double max); Set<byte[]> zrangeByScore(byte[] key, double min, double max);
Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
@@ -141,20 +143,37 @@ public interface BinaryJedisCommands {
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
int offset, int count); int offset, int count);
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max);
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max,
int offset, int count);
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min); Set<byte[]> zrevrangeByScore(byte[] key, double max, double min);
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
int offset, int count); int offset, int count);
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min);
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
int offset, int count);
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min); Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
int offset, int count); int offset, int count);
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min);
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min,
int offset, int count);
Long zremrangeByRank(byte[] key, int start, int end); Long zremrangeByRank(byte[] key, int start, int end);
Long zremrangeByScore(byte[] key, double start, double end); Long zremrangeByScore(byte[] key, double start, double end);
Long zremrangeByScore(byte[] key, byte[] start, byte[] end);
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
Long objectRefcount(byte[] key); Long objectRefcount(byte[] key);

View File

@@ -340,6 +340,11 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.zcount(key, min, max); return j.zcount(key, min, max);
} }
public Long zcount(byte[] key, byte[] min, byte[] max) {
Jedis j = getShard(key);
return j.zcount(key, min, max);
}
public Set<byte[]> zrangeByScore(byte[] key, double min, double max) { public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max); return j.zrangeByScore(key, min, max);
@@ -362,6 +367,18 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.zrangeByScoreWithScores(key, min, max, offset, count); return j.zrangeByScoreWithScores(key, min, max, offset, count);
} }
public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max);
}
public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min,
byte[] max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max, offset, count);
}
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) { public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min); return j.zrevrangeByScore(key, max, min);
@@ -385,6 +402,29 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.zrevrangeByScoreWithScores(key, max, min, offset, count); return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
} }
public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min);
}
public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count);
}
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max,
byte[] min) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min);
}
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max,
byte[] 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) { public Long zremrangeByRank(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByRank(key, start, end); return j.zremrangeByRank(key, start, end);
@@ -395,6 +435,11 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.zremrangeByScore(key, start, end); return j.zremrangeByScore(key, start, end);
} }
public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) {
Jedis j = getShard(key);
return j.zremrangeByScore(key, start, end);
}
public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot,
byte[] value) { byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);

View File

@@ -1,5 +1,7 @@
package redis.clients.jedis; package redis.clients.jedis;
import static redis.clients.jedis.Protocol.toByteArray;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -446,6 +448,10 @@ public class BinaryTransaction extends Queable {
} }
public Response<Long> zcount(byte[] key, double min, double max) { public Response<Long> zcount(byte[] key, double min, double max) {
return zcount(key, toByteArray(min), toByteArray(max));
}
public Response<Long> zcount(byte[] key, byte[] min, byte[] max) {
client.zcount(key, min, max); client.zcount(key, min, max);
return getResponse(BuilderFactory.LONG); return getResponse(BuilderFactory.LONG);
} }
@@ -473,8 +479,7 @@ public class BinaryTransaction extends Queable {
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min, public Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
double max) { double max) {
client.zrangeByScore(key, min, max); return zrangeByScore(key, toByteArray(min), toByteArray(max));
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
} }
public Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min, public Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
@@ -483,20 +488,35 @@ public class BinaryTransaction extends Queable {
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
} }
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min, public Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
double max, int offset, int count) { byte[] max, int offset, int count) {
client.zrangeByScore(key, min, max, offset, count); client.zrangeByScore(key, min, max, offset, count);
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
} }
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
double max, int offset, int count) {
return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count);
}
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min, public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
double max) { double max) {
client.zrangeByScoreWithScores(key, min, max); return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max));
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
} }
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min, public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
double max, int offset, int count) { double max, int offset, int count) {
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count);
}
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
byte[] max) {
client.zrangeByScoreWithScores(key, min, max);
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
}
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
byte[] max, int offset, int count) {
client.zrangeByScoreWithScores(key, min, max, offset, count); client.zrangeByScoreWithScores(key, min, max, offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
} }
@@ -522,6 +542,10 @@ public class BinaryTransaction extends Queable {
} }
public Response<Long> zremrangeByScore(byte[] key, double start, double end) { public Response<Long> zremrangeByScore(byte[] key, double start, double end) {
return zremrangeByScore(key, toByteArray(start), toByteArray(end));
}
public Response<Long> zremrangeByScore(byte[] key, byte[] start, byte[] end) {
client.zremrangeByScore(key, start, end); client.zremrangeByScore(key, start, end);
return getResponse(BuilderFactory.LONG); return getResponse(BuilderFactory.LONG);
} }

View File

@@ -405,12 +405,16 @@ public class Client extends BinaryClient implements Commands {
} }
public void zcount(final String key, final double min, final double max) { public void zcount(final String key, final double min, final double max) {
zcount(SafeEncoder.encode(key), min, max); zcount(SafeEncoder.encode(key), toByteArray(min), toByteArray(max));
}
public void zcount(final String key, final String min, final String max) {
zcount(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max));
} }
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max) { final double max) {
zrangeByScore(SafeEncoder.encode(key), min, max); zrangeByScore(SafeEncoder.encode(key), toByteArray(min), toByteArray(max));
} }
public void zrangeByScore(final String key, final String min, public void zrangeByScore(final String key, final String min,
@@ -421,23 +425,39 @@ public class Client extends BinaryClient implements Commands {
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max, final int offset, int count) { final double max, final int offset, int count) {
zrangeByScore(SafeEncoder.encode(key), min, max, offset, count); zrangeByScore(SafeEncoder.encode(key), toByteArray(min), toByteArray(max), offset, count);
} }
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max) { final double max) {
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max); zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), toByteArray(max));
} }
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max, final int offset, final int count) { final double max, final int offset, final int count) {
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), toByteArray(max), offset,
count); count);
} }
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min) { final double min) {
zrevrangeByScore(SafeEncoder.encode(key), max, min); zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), toByteArray(min));
}
public void zrangeByScore(final String key, final String min,
final String max, final int offset, int count) {
zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count);
}
public void zrangeByScoreWithScores(final String key, final String min,
final String max) {
zrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max));
}
public void zrangeByScoreWithScores(final String key, final String min,
final String max, final int offset, final int count) {
zrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max), offset,
count);
} }
public void zrevrangeByScore(final String key, final String max, public void zrevrangeByScore(final String key, final String max,
@@ -448,17 +468,33 @@ public class Client extends BinaryClient implements Commands {
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min, final int offset, int count) { final double min, final int offset, int count) {
zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count); zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), toByteArray(min), offset, count);
}
public void zrevrangeByScore(final String key, final String max,
final String min, final int offset, int count) {
zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min), offset, count);
} }
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min) { final double min) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min); zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), toByteArray(min));
}
public void zrevrangeByScoreWithScores(final String key, final String max,
final String min) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min));
} }
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min, final int offset, final int count) { final double min, final int offset, final int count) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min, offset, zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), toByteArray(min), offset,
count);
}
public void zrevrangeByScoreWithScores(final String key, final String max,
final String min, final int offset, final int count) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min), offset,
count); count);
} }
@@ -468,7 +504,12 @@ public class Client extends BinaryClient implements Commands {
public void zremrangeByScore(final String key, final double start, public void zremrangeByScore(final String key, final double start,
final double end) { final double end) {
zremrangeByScore(SafeEncoder.encode(key), start, end); zremrangeByScore(SafeEncoder.encode(key), toByteArray(start), toByteArray(end));
}
public void zremrangeByScore(final String key, final String start,
final String end) {
zremrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(start), SafeEncoder.encode(end));
} }
public void zunionstore(final String dstkey, final String... sets) { public void zunionstore(final String dstkey, final String... sets) {

View File

@@ -184,6 +184,8 @@ public interface Commands {
public void zcount(final String key, final double min, final double max); public void zcount(final String key, final double min, final double max);
public void zcount(final String key, final String min, final String max);
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max); final double max);
@@ -199,6 +201,12 @@ public interface Commands {
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max, final int offset, final int count); final double max, final int offset, final int count);
public void zrangeByScoreWithScores(final String key, final String min,
final String max);
public void zrangeByScoreWithScores(final String key, final String min,
final String max, final int offset, final int count);
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min); final double min);
@@ -214,11 +222,20 @@ public interface Commands {
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min, final int offset, final int count); final double min, final int offset, final int count);
public void zrevrangeByScoreWithScores(final String key, final String max,
final String min);
public void zrevrangeByScoreWithScores(final String key, final String max,
final String min, final int offset, final int count);
public void zremrangeByRank(final String key, final int start, final int end); public void zremrangeByRank(final String key, final int start, final int end);
public void zremrangeByScore(final String key, final double start, public void zremrangeByScore(final String key, final double start,
final double end); final double end);
public void zremrangeByScore(final String key, final String start,
final String end);
public void zunionstore(final String dstkey, final String... sets); public void zunionstore(final String dstkey, final String... sets);
public void zunionstore(final String dstkey, final ZParams params, public void zunionstore(final String dstkey, final ZParams params,

View File

@@ -1992,6 +1992,12 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return client.getIntegerReply(); return client.getIntegerReply();
} }
public Long zcount(final String key, final String min, final String max) {
checkIsInMulti();
client.zcount(key, min, max);
return client.getIntegerReply();
}
/** /**
* Return the all the elements in the sorted set at key with a score between * 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). * min and max (including elements with score equal to min or max).
@@ -2126,6 +2132,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return new LinkedHashSet<String>(client.getMultiBulkReply()); return new LinkedHashSet<String>(client.getMultiBulkReply());
} }
public Set<String> zrangeByScore(final String key, final String min,
final String max, final int offset, final int count) {
checkIsInMulti();
client.zrangeByScore(key, min, max, offset, count);
return new LinkedHashSet<String>(client.getMultiBulkReply());
}
/** /**
* Return the all the elements in the sorted set at key with a score between * 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). * min and max (including elements with score equal to min or max).
@@ -2190,6 +2203,14 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return set; return set;
} }
public Set<Tuple> zrangeByScoreWithScores(final String key,
final String min, final String max) {
checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max);
Set<Tuple> set = getTupledSet();
return set;
}
/** /**
* Return the all the elements in the sorted set at key with a score between * 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). * min and max (including elements with score equal to min or max).
@@ -2255,6 +2276,15 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return set; return set;
} }
public Set<Tuple> zrangeByScoreWithScores(final String key,
final String min, final String max, final int offset,
final int count) {
checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max, offset, count);
Set<Tuple> set = getTupledSet();
return set;
}
private Set<Tuple> getTupledSet() { private Set<Tuple> getTupledSet() {
checkIsInMulti(); checkIsInMulti();
List<String> membersWithScores = client.getMultiBulkReply(); List<String> membersWithScores = client.getMultiBulkReply();
@@ -2304,6 +2334,30 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return set; return set;
} }
public Set<Tuple> zrevrangeByScoreWithScores(final String key,
final String max, final String min, final int offset,
final int count) {
checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
Set<Tuple> set = getTupledSet();
return set;
}
public Set<String> zrevrangeByScore(final String key, final String max,
final String 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 String max, final String min) {
checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min);
Set<Tuple> set = getTupledSet();
return set;
}
/** /**
* Remove all elements in the sorted set at key with rank between start and * 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 * end. Start and end are 0-based with rank 0 being the element with the
@@ -2344,6 +2398,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return client.getIntegerReply(); return client.getIntegerReply();
} }
public Long zremrangeByScore(final String key, final String start,
final String end) {
checkIsInMulti();
client.zremrangeByScore(key, start, end);
return client.getIntegerReply();
}
/** /**
* Creates a union or intersection of N sorted sets given by keys k1 through * Creates a union or intersection of N sorted sets given by keys k1 through
* kN, and stores it at dstkey. It is mandatory to provide the number of * kN, and stores it at dstkey. It is mandatory to provide the number of

View File

@@ -136,13 +136,22 @@ public interface JedisCommands {
Long zcount(String key, double min, double max); Long zcount(String key, double min, double max);
Long zcount(String key, String min, String max);
Set<String> zrangeByScore(String key, double min, double max); Set<String> zrangeByScore(String key, double min, double max);
Set<String> zrangeByScore(String key, String min, String max);
Set<String> zrevrangeByScore(String key, double max, double min); Set<String> zrevrangeByScore(String key, double max, double min);
Set<String> zrangeByScore(String key, double min, double max, int offset, Set<String> zrangeByScore(String key, double min, double max, int offset,
int count); int count);
Set<String> zrevrangeByScore(String key, String max, String min);
Set<String> zrangeByScore(String key, String min, String max, int offset,
int count);
Set<String> zrevrangeByScore(String key, double max, double min, Set<String> zrevrangeByScore(String key, double max, double min,
int offset, int count); int offset, int count);
@@ -153,13 +162,28 @@ public interface JedisCommands {
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, Set<Tuple> zrangeByScoreWithScores(String key, double min, double max,
int offset, int count); int offset, int count);
Set<String> zrevrangeByScore(String key, String max, String min,
int offset, int count);
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max);
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min);
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max,
int offset, int count);
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min,
int offset, int count); int offset, int count);
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min,
int offset, int count);
Long zremrangeByRank(String key, int start, int end); Long zremrangeByRank(String key, int start, int end);
Long zremrangeByScore(String key, double start, double end); Long zremrangeByScore(String key, double start, double end);
Long zremrangeByScore(String key, String start, String end);
Long linsert(String key, Client.LIST_POSITION where, String pivot, Long linsert(String key, Client.LIST_POSITION where, String pivot,
String value); String value);
} }

View File

@@ -1,5 +1,6 @@
package redis.clients.jedis; package redis.clients.jedis;
import static redis.clients.jedis.Protocol.toByteArray;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -842,7 +843,7 @@ public class Pipeline extends Queable {
} }
public Response<Long> zcount(byte[] key, double min, double max) { public Response<Long> zcount(byte[] key, double min, double max) {
client.zcount(key, min, max); client.zcount(key, toByteArray(min), toByteArray(max));
return getResponse(BuilderFactory.LONG); return getResponse(BuilderFactory.LONG);
} }
@@ -896,8 +897,7 @@ public class Pipeline extends Queable {
public Response<Set<String>> zrangeByScore(byte[] key, double min, public Response<Set<String>> zrangeByScore(byte[] key, double min,
double max) { double max) {
client.zrangeByScore(key, min, max); return zrangeByScore(key, toByteArray(min), toByteArray(max));
return getResponse(BuilderFactory.STRING_ZSET);
} }
public Response<Set<String>> zrangeByScore(String key, String min, public Response<Set<String>> zrangeByScore(String key, String min,
@@ -920,6 +920,11 @@ public class Pipeline extends Queable {
public Response<Set<String>> zrangeByScore(byte[] key, double min, public Response<Set<String>> zrangeByScore(byte[] key, double min,
double max, int offset, int count) { double max, int offset, int count) {
return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count);
}
public Response<Set<String>> zrangeByScore(byte[] key, byte[] min,
byte[] max, int offset, int count) {
client.zrangeByScore(key, min, max, offset, count); client.zrangeByScore(key, min, max, offset, count);
return getResponse(BuilderFactory.STRING_ZSET); return getResponse(BuilderFactory.STRING_ZSET);
} }
@@ -932,6 +937,11 @@ public class Pipeline extends Queable {
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min, public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
double max) { double max) {
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max));
}
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
byte[] max) {
client.zrangeByScoreWithScores(key, min, max); client.zrangeByScoreWithScores(key, min, max);
return getResponse(BuilderFactory.TUPLE_ZSET); return getResponse(BuilderFactory.TUPLE_ZSET);
} }
@@ -944,6 +954,12 @@ public class Pipeline extends Queable {
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min, public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
double max, int offset, int count) { double max, int offset, int count) {
client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
byte[] max, int offset, int count) {
client.zrangeByScoreWithScores(key, min, max, offset, count); client.zrangeByScoreWithScores(key, min, max, offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET); return getResponse(BuilderFactory.TUPLE_ZSET);
} }
@@ -956,7 +972,7 @@ public class Pipeline extends Queable {
public Response<Set<String>> zrevrangeByScore(byte[] key, double max, public Response<Set<String>> zrevrangeByScore(byte[] key, double max,
double min) { double min) {
client.zrevrangeByScore(key, max, min); client.zrevrangeByScore(key, toByteArray(max), toByteArray(min));
return getResponse(BuilderFactory.STRING_ZSET); return getResponse(BuilderFactory.STRING_ZSET);
} }
@@ -980,6 +996,12 @@ public class Pipeline extends Queable {
public Response<Set<String>> zrevrangeByScore(byte[] key, double max, public Response<Set<String>> zrevrangeByScore(byte[] key, double max,
double min, int offset, int count) { double min, int offset, int count) {
client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response<Set<String>> zrevrangeByScore(byte[] key, byte[] max,
byte[] min, int offset, int count) {
client.zrevrangeByScore(key, max, min, offset, count); client.zrevrangeByScore(key, max, min, offset, count);
return getResponse(BuilderFactory.STRING_ZSET); return getResponse(BuilderFactory.STRING_ZSET);
} }
@@ -992,6 +1014,12 @@ public class Pipeline extends Queable {
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
double max, double min) { double max, double min) {
client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min));
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
byte[] max, byte[] min) {
client.zrevrangeByScoreWithScores(key, max, min); client.zrevrangeByScoreWithScores(key, max, min);
return getResponse(BuilderFactory.TUPLE_ZSET); return getResponse(BuilderFactory.TUPLE_ZSET);
} }
@@ -1004,6 +1032,12 @@ public class Pipeline extends Queable {
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
double max, double min, int offset, int count) { double max, double min, int offset, int count) {
client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET);
}
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
byte[] max, byte[] min, int offset, int count) {
client.zrevrangeByScoreWithScores(key, max, min, offset, count); client.zrevrangeByScoreWithScores(key, max, min, offset, count);
return getResponse(BuilderFactory.TUPLE_ZSET); return getResponse(BuilderFactory.TUPLE_ZSET);
} }
@@ -1054,6 +1088,11 @@ public class Pipeline extends Queable {
} }
public Response<Long> zremrangeByScore(byte[] key, double start, double end) { public Response<Long> zremrangeByScore(byte[] key, double start, double end) {
client.zremrangeByScore(key, toByteArray(start), toByteArray(end));
return getResponse(BuilderFactory.LONG);
}
public Response<Long> zremrangeByScore(byte[] key, byte[] start, byte[] end) {
client.zremrangeByScore(key, start, end); client.zremrangeByScore(key, start, end);
return getResponse(BuilderFactory.LONG); return getResponse(BuilderFactory.LONG);
} }

View File

@@ -358,6 +358,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.zcount(key, min, max); return j.zcount(key, min, max);
} }
public Long zcount(String key, String min, String max) {
Jedis j = getShard(key);
return j.zcount(key, min, max);
}
public Set<String> zrangeByScore(String key, double min, double max) { public Set<String> zrangeByScore(String key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max); return j.zrangeByScore(key, min, max);
@@ -403,6 +408,51 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.zrevrangeByScoreWithScores(key, max, min, offset, count); return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
} }
public Set<String> zrangeByScore(String key, String min, String max) {
Jedis j = getShard(key);
return j.zrangeByScore(key, min, max);
}
public Set<String> zrevrangeByScore(String key, String max, String min) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min);
}
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);
}
public Set<String> zrevrangeByScore(String key, String max, String min,
int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count);
}
public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max);
}
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max,
String min) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min);
}
public Set<Tuple> zrangeByScoreWithScores(String key, String min,
String max, int offset, int count) {
Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max, offset, count);
}
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max,
String 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) { public Long zremrangeByRank(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByRank(key, start, end); return j.zremrangeByRank(key, start, end);
@@ -413,6 +463,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.zremrangeByScore(key, start, end); return j.zremrangeByScore(key, start, end);
} }
public Long zremrangeByScore(String key, String start, String end) {
Jedis j = getShard(key);
return j.zremrangeByScore(key, start, end);
}
public Long linsert(String key, LIST_POSITION where, String pivot, public Long linsert(String key, LIST_POSITION where, String pivot,
String value) { String value) {
Jedis j = getShard(key); Jedis j = getShard(key);

View File

@@ -373,6 +373,10 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
assertEquals(2, result); assertEquals(2, result);
result = jedis.zcount("foo", "(0.01", "+inf");
assertEquals(3, result);
// Binary // Binary
jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 1d, ba);
jedis.zadd(bfoo, 10d, bb); jedis.zadd(bfoo, 10d, bb);
@@ -383,6 +387,9 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
assertEquals(2, bresult); assertEquals(2, bresult);
bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), SafeEncoder.encode("+inf"));
assertEquals(3, bresult);
} }
@Test @Test