Skip to content

Commit

Permalink
added zrangebyscore command support
Browse files Browse the repository at this point in the history
  • Loading branch information
jackygurui committed Nov 15, 2015
1 parent 74e75de commit 6f029c8
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/main/java/org/redisson/RedissonScoredSortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,52 @@ public Future<Collection<ScoredEntry<V>>> entryRangeAsync(int startIndex, int en
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGE_ENTRY, getName(), startIndex, endIndex, "WITHSCORES");
}

@Override
public Collection<V> valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
return get(valueRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive));
}

@Override
public Future<Collection<V>> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive);
String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive);
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE, getName(), startValue, endValue);
}

@Override
public Collection<ScoredEntry<V>> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
return get(entryRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive));
}

@Override
public Future<Collection<ScoredEntry<V>>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive);
String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive);
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE_ENTRY, getName(), startValue, endValue, "WITHSCORES");
}

@Override
public Collection<V> valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
return get(valueRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count));
}

@Override
public Future<Collection<V>> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive);
String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive);
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE, getName(), startValue, endValue, "LIMIT", offset, count);
}

@Override
public Collection<ScoredEntry<V>> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
return get(entryRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count));
}

@Override
public Future<Collection<ScoredEntry<V>>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive);
String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive);
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE_ENTRY, getName(), startValue, endValue, "WITHSCORES", "LIMIT", offset, count);
}

}
2 changes: 2 additions & 0 deletions src/main/java/org/redisson/client/protocol/RedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public interface RedisCommands {
RedisStrictCommand<Integer> ZREMRANGEBYSCORE = new RedisStrictCommand<Integer>("ZREMRANGEBYSCORE", new IntegerReplayConvertor());
RedisStrictCommand<Integer> ZREMRANGEBYLEX = new RedisStrictCommand<Integer>("ZREMRANGEBYLEX", new IntegerReplayConvertor());
RedisCommand<List<Object>> ZRANGEBYLEX = new RedisCommand<List<Object>>("ZRANGEBYLEX", new ObjectListReplayDecoder<Object>());
RedisCommand<List<Object>> ZRANGEBYSCORE = new RedisCommand<List<Object>>("ZRANGEBYSCORE", new ObjectListReplayDecoder<Object>());
RedisCommand<List<ScoredEntry<Object>>> ZRANGE_ENTRY = new RedisCommand<List<ScoredEntry<Object>>>("ZRANGE", new ScoredSortedSetReplayDecoder<Object>());
RedisCommand<List<ScoredEntry<Object>>> ZRANGEBYSCORE_ENTRY = new RedisCommand<List<ScoredEntry<Object>>>("ZRANGEBYSCORE", new ScoredSortedSetReplayDecoder<Object>());
RedisCommand<ListScanResult<Object>> ZSCAN = new RedisCommand<ListScanResult<Object>>("ZSCAN", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ScoredSortedSetScanReplayDecoder()), ValueType.OBJECT);
RedisStrictCommand<Double> ZINCRBY = new RedisStrictCommand<Double>("ZINCRBY", new DoubleReplayConvertor());

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/redisson/core/RScoredSortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<

Collection<ScoredEntry<V>> entryRange(int startIndex, int endIndex);

Collection<V> valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);

Collection<ScoredEntry<V>> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);

Collection<V> valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);

Collection<ScoredEntry<V>> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);

}
8 changes: 8 additions & 0 deletions src/main/java/org/redisson/core/RScoredSortedSetAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync {

Future<Collection<ScoredEntry<V>>> entryRangeAsync(int startIndex, int endIndex);

Future<Collection<V>> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);

Future<Collection<ScoredEntry<V>>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);

Future<Collection<V>> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);

Future<Collection<ScoredEntry<V>>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);

}
33 changes: 33 additions & 0 deletions src/test/java/org/redisson/RedissonScoredSortedSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,39 @@ public void testLexSortedSet() {
Assert.assertArrayEquals(new String[]{"c", "d"}, a);
}

@Test
public void testScoredSortedSetValueRange() {
RScoredSortedSet<String> set = redisson.<String>getScoredSortedSet("simple");

set.add(0, "a");
set.add(1, "b");
set.add(2, "c");
set.add(3, "d");
set.add(4, "e");

Collection<String> r = set.valueRange(1, true, 4, false, 1, 2);
String[] a = r.toArray(new String[0]);
Assert.assertArrayEquals(new String[]{"c", "d"}, a);
}

@Test
public void testScoredSortedSetEntryRange() {
RScoredSortedSet<String> set = redisson.<String>getScoredSortedSet("simple");

set.add(0, "a");
set.add(1, "b");
set.add(2, "c");
set.add(3, "d");
set.add(4, "e");

Collection<ScoredEntry<String>> r = set.entryRange(1, true, 4, false, 1, 2);
ScoredEntry<String>[] a = r.toArray(new ScoredEntry[0]);
Assert.assertEquals(2d, a[0].getScore(), 0);
Assert.assertEquals(3d, a[1].getScore(), 0);
Assert.assertEquals("c", a[0].getValue());
Assert.assertEquals("d", a[1].getValue());
}

@Test
public void testAddAndGet() throws InterruptedException {
RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("simple");
Expand Down

0 comments on commit 6f029c8

Please sign in to comment.