Added the ability to use Double.MIN_VALUE and Double.MAX_VALUE when calling sorted set methods to represent "-inf" and "+inf" respectively.

This commit is contained in:
Hisham Mardam-Bey
2011-06-09 23:24:56 -04:00
parent f9608e9364
commit 03d4208318
2 changed files with 47 additions and 11 deletions

View File

@@ -496,17 +496,29 @@ public class BinaryClient extends Connection {
}
public void zcount(final byte[] key, final double min, final double max) {
sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max));
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax);
}
public void zrangeByScore(final byte[] key, final double min,
final double max) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max));
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
}
public void zrevrangeByScore(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min));
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin);
}
public void zrangeByScore(final byte[] key, final byte[] min,
@@ -521,38 +533,62 @@ public class BinaryClient extends Connection {
public void zrangeByScore(final byte[] key, final double min,
final double max, final int offset, int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
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),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
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),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
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),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
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),
byte byteArrayMin[] = (min == Double.MIN_VALUE) ? "-inf".getBytes() : toByteArray(min);
byte byteArrayMax[] = (max == Double.MAX_VALUE) ? "+inf".getBytes() : toByteArray(max);
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}

View File

@@ -2047,8 +2047,8 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @see #zcount(String, double, double)
*
* @param key
* @param min
* @param max
* @param min a double or Double.MIN_VALUE for "-inf"
* @param max a double or Double.MAX_VALUE for "+inf"
* @return Multi bulk reply specifically a list of elements in the specified
* score range.
*/