Skip to content

Commit

Permalink
Now methods accepting infinit and exclusions are supported as String …
Browse files Browse the repository at this point in the history
…and byte[] overloads
  • Loading branch information
ivowiblo committed May 4, 2012
1 parent 5244d82 commit 129e358
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 87 deletions.
56 changes: 23 additions & 33 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Expand Up @@ -527,18 +527,8 @@ public void punsubscribe(final byte[]... patterns) {
sendCommand(PUNSUBSCRIBE, patterns);
}

public void zcount(final byte[] key, final double min, final double max) {
sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(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 zcount(final byte[] key, final byte[] min, final byte[] max) {
sendCommand(ZCOUNT, key, min, max);
}

public void zrangeByScore(final byte[] key, final byte[] min,
Expand All @@ -551,40 +541,40 @@ public void zrevrangeByScore(final byte[] key, final byte[] max,
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),
public void zrangeByScore(final byte[] key, final byte[] min,
final byte[] max, final int offset, int count) {
sendCommand(ZRANGEBYSCORE, key, min, 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),
public void zrevrangeByScore(final byte[] key, final byte[] max,
final byte[] min, final int offset, int count) {
sendCommand(ZREVRANGEBYSCORE, key, max, 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),
public void zrangeByScoreWithScores(final byte[] key, final byte[] min,
final byte[] max) {
sendCommand(ZRANGEBYSCORE, key, min, max,
WITHSCORES.raw);
}

public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max,
final byte[] min) {
sendCommand(ZREVRANGEBYSCORE, key, max, min,
WITHSCORES.raw);
}

public void zrangeByScoreWithScores(final byte[] key, final double min,
final double max, final int offset, final int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
public void zrangeByScoreWithScores(final byte[] key, final byte[] min,
final byte[] max, final int offset, final int count) {
sendCommand(ZRANGEBYSCORE, key, min, max,
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),
public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max,
final byte[] min, final int offset, final int count) {
sendCommand(ZREVRANGEBYSCORE, key, max, min,
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}
Expand All @@ -593,9 +583,9 @@ public void zremrangeByRank(final byte[] key, final int start, final int end) {
sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end));
}

public void zremrangeByScore(final byte[] key, final double start,
final double end) {
sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end));
public void zremrangeByScore(final byte[] key, final byte[] start,
final byte[] end) {
sendCommand(ZREMRANGEBYSCORE, key, start, end);
}

public void zunionstore(final byte[] dstkey, final byte[]... sets) {
Expand Down
97 changes: 67 additions & 30 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Expand Up @@ -2064,11 +2064,15 @@ public void psubscribe(final JedisPubSub jedisPubSub,
}

public Long zcount(final byte[] key, final double min, final double max) {
checkIsInMulti();
client.zcount(key, min, max);
return client.getIntegerReply();
return zcount(key, toByteArray(min), toByteArray(max));
}


public Long zcount(final byte[] key, final byte[] min, final byte[] 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
* min and max (including elements with score equal to min or max).
Expand Down Expand Up @@ -2127,10 +2131,8 @@ public Long zcount(final byte[] key, final double min, final double max) {
*/
public Set<byte[]> zrangeByScore(final byte[] key, final double min,
final double max) {
checkIsInMulti();
client.zrangeByScore(key, min, max);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
}
return zrangeByScore(key, toByteArray(min), toByteArray(max));
}

public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
final byte[] max) {
Expand Down Expand Up @@ -2197,10 +2199,15 @@ public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
*/
public Set<byte[]> zrangeByScore(final byte[] key, final double min,
final double max, final int offset, final int count) {
checkIsInMulti();
client.zrangeByScore(key, min, max, offset, count);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
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();
client.zrangeByScore(key, min, max, offset, count);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
}

/**
* Return the all the elements in the sorted set at key with a score between
Expand Down Expand Up @@ -2260,11 +2267,16 @@ public Set<byte[]> zrangeByScore(final byte[] key, final double min,
*/
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final double min, final double max) {
checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max);
Set<Tuple> set = getBinaryTupledSet();
return set;
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max));
}

public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final byte[] min, final byte[] max) {
checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max);
Set<Tuple> set = getBinaryTupledSet();
return set;
}

/**
* Return the all the elements in the sorted set at key with a score between
Expand Down Expand Up @@ -2325,11 +2337,17 @@ public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
final double min, final double max, final int offset,
final int count) {
checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max, offset, count);
Set<Tuple> set = getBinaryTupledSet();
return set;
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();
client.zrangeByScoreWithScores(key, min, max, offset, count);
Set<Tuple> set = getBinaryTupledSet();
return set;
}

private Set<Tuple> getBinaryTupledSet() {
checkIsInMulti();
Expand All @@ -2345,9 +2363,7 @@ private Set<Tuple> getBinaryTupledSet() {

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());
return zrevrangeByScore(key, toByteArray(max), toByteArray(min));
}

public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
Expand All @@ -2359,27 +2375,43 @@ public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,

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());
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();
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) {
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();
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 byte[] max, final byte[] 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
Expand Down Expand Up @@ -2416,10 +2448,15 @@ public Long zremrangeByRank(final byte[] key, final int start, final int end) {
*/
public Long zremrangeByScore(final byte[] key, final double start,
final double end) {
checkIsInMulti();
client.zremrangeByScore(key, start, end);
return client.getIntegerReply();
return zremrangeByScore(key, toByteArray(start), toByteArray(end));
}

public Long zremrangeByScore(final byte[] key, final byte[] start,
final byte[] end) {
checkIsInMulti();
client.zremrangeByScore(key, start, end);
return client.getIntegerReply();
}

/**
* Creates a union or intersection of N sorted sets given by keys k1 through
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCommands.java
Expand Up @@ -131,6 +131,8 @@ public interface BinaryJedisCommands {

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, int offset,
Expand All @@ -141,20 +143,37 @@ Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
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,
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,
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 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 objectRefcount(byte[] key);
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Expand Up @@ -339,6 +339,11 @@ public Long zcount(byte[] key, double min, double max) {
Jedis j = getShard(key);
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) {
Jedis j = getShard(key);
Expand All @@ -361,6 +366,18 @@ public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
Jedis j = getShard(key);
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) {
Jedis j = getShard(key);
Expand All @@ -384,6 +401,29 @@ public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
Jedis j = getShard(key);
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) {
Jedis j = getShard(key);
Expand All @@ -395,6 +435,11 @@ public Long zremrangeByScore(byte[] key, double start, double 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,
byte[] value) {
Jedis j = getShard(key);
Expand Down

0 comments on commit 129e358

Please sign in to comment.