Skip to content

Commit

Permalink
added lexRange methods with limit options
Browse files Browse the repository at this point in the history
  • Loading branch information
jackygurui committed Nov 14, 2015
1 parent f48681c commit 74e75de
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/java/org/redisson/RedissonLexSortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,41 @@ public Future<Collection<String>> lexRangeAsync(String fromElement, boolean from
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue);
}

@Override
public Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count) {
return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive, offset, count));
}

@Override
public Collection<String> lexRangeHead(String toElement, boolean toInclusive, int offset, int count) {
return get(lexRangeHeadAsync(toElement, toInclusive, offset, count));
}

@Override
public Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive, int offset, int count) {
String toValue = value(toElement, toInclusive);
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue, "LIMIT", offset, count);
}

@Override
public Collection<String> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count) {
return get(lexRangeTailAsync(fromElement, fromInclusive, offset, count));
}

@Override
public Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive, int offset, int count) {
String fromValue = value(fromElement, fromInclusive);
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+", "LIMIT", offset, count);
}

@Override
public Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count) {
String fromValue = value(fromElement, fromInclusive);
String toValue = value(toElement, toInclusive);

return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue, "LIMIT", offset, count);
}

@Override
public int lexCountTail(String fromElement, boolean fromInclusive) {
return get(lexCountTailAsync(fromElement, fromInclusive));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/redisson/core/RLexSortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public interface RLexSortedSet extends RLexSortedSetAsync, Set<String>, RExpirab

Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);

Collection<String> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count);

Collection<String> lexRangeHead(String toElement, boolean toInclusive, int offset, int count);

Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);

int lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);

int rank(String o);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/redisson/core/RLexSortedSetAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public interface RLexSortedSetAsync extends RCollectionAsync<String> {

Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);

Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive, int offset, int count);

Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive, int offset, int count);

Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);

Future<Integer> lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);

Future<Integer> rankAsync(String o);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/redisson/RedissonScoredSortedSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.core.RLexSortedSet;
import org.redisson.core.RScoredSortedSet;
import org.redisson.core.RSortedSet;

Expand Down Expand Up @@ -438,6 +439,20 @@ public void testEntryRange() {
new ScoredEntry<Integer>(50D, 5)));
}

@Test
public void testLexSortedSet() {
RLexSortedSet set = redisson.getLexSortedSet("simple");

set.add("a");
set.add("b");
set.add("c");
set.add("d");
set.add("e");

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

@Test
public void testAddAndGet() throws InterruptedException {
Expand Down

0 comments on commit 74e75de

Please sign in to comment.