Skip to content

Commit

Permalink
Support for
Browse files Browse the repository at this point in the history
sorted set commands ZLEXCOUNT, ZRANGEBYLEX, ZREMRANGEBYLEX
  • Loading branch information
mp911de committed Jun 17, 2014
1 parent 25577c3 commit c6722f5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Lettuce works with:

Currently following commands are __not yet__ supported:

* Sorted Sets: ZLEXCOUNT, ZRANGEBYLEX, ZREMRANGEBYLEX
* Server Commands: DEBUG SEGFAULT, MONITOR, PUBSUB

I'm pursuing the client code as a fork since the latest changes weren't merged back into https://github/wg/lettuce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,26 @@ public RedisFuture<List<String>> clusterSlaves(String nodeId) {
return dispatch(commandBuilder.clusterSlaves(nodeId));
}

@Override
public RedisFuture<Long> zlexcount(K key, String min, String max) {
return dispatch(commandBuilder.zlexcount(key, min, max));
}

@Override
public RedisFuture<Long> zremrangebylex(K key, String min, String max) {
return dispatch(commandBuilder.zremrangebylex(key, min, max));
}

@Override
public RedisFuture<List<V>> zrangebylex(K key, String min, String max) {
return dispatch(commandBuilder.zrangebylex(key, min, max));
}

@Override
public RedisFuture<List<V>> zrangebylex(K key, String min, String max, long offset, long count) {
return dispatch(commandBuilder.zrangebylex(key, min, max, offset, count));
}

public <T> RedisCommand<K, V, T> dispatch(CommandType type, CommandOutput<K, V, T> output) {
return dispatch(type, output, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandOutput;
import com.lambdaworks.redis.protocol.RedisCommand;
import com.lambdaworks.redis.protocol.SetArgs;

/**
Expand Down Expand Up @@ -1087,6 +1088,30 @@ public Command<K, V, Long> zunionstore(K destination, ZStoreArgs storeArgs, K...
return createCommand(ZUNIONSTORE, new IntegerOutput<K, V>(codec), args);
}

public RedisCommand<K, V, Long> zlexcount(K key, String min, String max) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
args.addKey(key).add(min).add(max);
return createCommand(ZLEXCOUNT, new IntegerOutput<K, V>(codec), args);
}

public RedisCommand<K, V, Long> zremrangebylex(K key, String min, String max) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
args.addKey(key).add(min).add(max);
return createCommand(ZREMRANGEBYLEX, new IntegerOutput<K, V>(codec), args);
}

public RedisCommand<K, V, List<V>> zrangebylex(K key, String min, String max) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
args.addKey(key).add(min).add(max);
return createCommand(ZRANGEBYLEX, new ValueListOutput<K, V>(codec), args);
}

public RedisCommand<K, V, List<V>> zrangebylex(K key, String min, String max, long offset, long count) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
args.addKey(key).add(min).add(max).add(LIMIT).add(offset).add(count);
return createCommand(ZRANGEBYLEX, new ValueListOutput<K, V>(codec), args);
}

public Command<K, V, List<V>> time() {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
return createCommand(TIME, new ValueListOutput<K, V>(codec), args);
Expand Down Expand Up @@ -1403,4 +1428,5 @@ public Command<K, V, String> clusterReset(boolean hard) {
}
return createCommand(CLUSTER, new StatusOutput<K, V>(codec), args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,12 @@ RedisFuture<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> chan
RedisFuture<StreamScanCursor> zscan(ScoredValueStreamingChannel<V> channel, K key, ScanCursor scanCursor, ScanArgs scanArgs);

RedisFuture<StreamScanCursor> zscan(ScoredValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

RedisFuture<Long> zlexcount(K key, String min, String max);

RedisFuture<Long> zremrangebylex(K key, String min, String max);

RedisFuture<List<V>> zrangebylex(K key, String min, String max);

RedisFuture<List<V>> zrangebylex(K key, String min, String max, long offset, long count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, S
StreamScanCursor zscan(ScoredValueStreamingChannel<V> channel, K key, ScanCursor scanCursor, ScanArgs scanArgs);

StreamScanCursor zscan(ScoredValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

Long zlexcount(K key, String min, String max);

Long zremrangebylex(K key, String min, String max);

List<V> zrangebylex(K key, String min, String max);

List<V> zrangebylex(K key, String min, String max, long offset, long count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public enum CommandType {

// Sorted Set

ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTERSTORE, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE, ZREVRANK, ZSCORE, ZUNIONSTORE, ZSCAN,
ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTERSTORE, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE, ZREVRANK, ZSCORE, ZUNIONSTORE, ZSCAN, ZLEXCOUNT, ZREMRANGEBYLEX, ZRANGEBYLEX,

// Scripting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.junit.Assert.assertTrue;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.Test;
Expand Down Expand Up @@ -304,6 +305,38 @@ public void zscanMatch() throws Exception {
assertEquals(100, cursor.getValues().size());
}

@Test
public void zlexcount() throws Exception {
setup100KeyValues(new HashSet<String>());
Long result = redis.zlexcount(key, "-", "+");

assertEquals(100, result.longValue());

Long resultFromTo = redis.zlexcount(key, "[value", "[zzz");
assertEquals(100, resultFromTo.longValue());
}

@Test
public void zrangebylex() throws Exception {
setup100KeyValues(new HashSet<String>());
List<String> result = redis.zrangebylex(key, "-", "+");

assertEquals(100, result.size());

List<String> result2 = redis.zrangebylex(key, "-", "+", 10, 10);

assertEquals(10, result2.size());
}

@Test
public void zremrangebylex() throws Exception {
setup100KeyValues(new HashSet<String>());
Long result = redis.zremrangebylex(key, "(aaa", "[zzz");

assertEquals(100, result.longValue());

}

protected void setup100KeyValues(Set<String> expect) {
for (int i = 0; i < 100; i++) {
redis.zadd(key + 1, i, value + i);
Expand Down

0 comments on commit c6722f5

Please sign in to comment.