Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,18 @@ public void zadd(final byte[] key, final Map<byte[], Double> scoreMembers, final
sendCommand(ZADD, params.getByteParams(key, argsArray));
}

public void zdiff(final byte[]... keys) {
sendCommand(ZDIFF, joinParameters(toByteArray(keys.length), keys));
}

public void zdiffWithScores(final byte[]... keys) {
final List<byte[]> args = new ArrayList<>(keys.length + 2);
args.add(toByteArray(keys.length));
Collections.addAll(args, keys);
args.add(WITHSCORES.getRaw());
sendCommand(ZDIFF, args.toArray(new byte[args.size()][]));
}

public void zaddIncr(final byte[] key, final double score, final byte[] member, final ZAddParams params) {
sendCommand(ZADD, params.getByteParams(key, INCR.getRaw(), toByteArray(score), member));
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,20 @@ public Long zcount(final byte[] key, final byte[] min, final byte[] max) {
return client.getIntegerReply();
}

@Override
public Set<byte[]> zdiff(final byte[]... keys) {
checkIsInMultiOrPipeline();
client.zdiff(keys);
return SetFromList.of(client.getBinaryMultiBulkReply());
}

@Override
public Set<Tuple> zdiffWithScores(final byte[]... keys) {
checkIsInMultiOrPipeline();
client.zdiffWithScores(keys);
return getTupledSet();
}

/**
* 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
20 changes: 20 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,26 @@ public Double execute(Jedis connection) {
}.runBinary(key);
}

@Override
public Set<byte[]> zdiff(final byte[]... keys) {
return new JedisClusterCommand<Set<byte[]>>(connectionHandler, maxAttempts) {
@Override
public Set<byte[]> execute(Jedis connection) {
return connection.zdiff(keys);
}
}.runBinary(keys.length, keys);
}

@Override
public Set<Tuple> zdiffWithScores(final byte[]... keys) {
return new JedisClusterCommand<Set<Tuple>>(connectionHandler, maxAttempts) {
@Override
public Set<Tuple> execute(Jedis connection) {
return connection.zdiffWithScores(keys);
}
}.runBinary(keys.length, keys);
}

@Override
public Set<byte[]> zrange(final byte[] key, final long start, final long stop) {
return new JedisClusterCommand<Set<byte[]>>(connectionHandler, maxAttempts) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,16 @@ public void zaddIncr(final String key, final double score, final String member,
zaddIncr(SafeEncoder.encode(key), score, SafeEncoder.encode(member), params);
}

@Override
public void zdiff(final String... keys) {
zdiff(SafeEncoder.encodeMany(keys));
}

@Override
public void zdiffWithScores(final String... keys) {
zdiffWithScores(SafeEncoder.encodeMany(keys));
}

@Override
public void zrange(final String key, final long start, final long stop) {
zrange(SafeEncoder.encode(key), start, stop);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,20 @@ public Double zaddIncr(final String key, final double score, final String member
return BuilderFactory.DOUBLE.build(client.getOne());
}

@Override
public Set<String> zdiff(String... keys) {
checkIsInMultiOrPipeline();
client.zdiff(keys);
return SetFromList.of(client.getMultiBulkReply());
}

@Override
public Set<Tuple> zdiffWithScores(String... keys) {
checkIsInMultiOrPipeline();
client.zdiffWithScores(keys);
return getTupledSet();
}

@Override
public Set<String> zrange(final String key, final long start, final long stop) {
checkIsInMultiOrPipeline();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,26 @@ public Double execute(Jedis connection) {
}.run(key);
}

@Override
public Set<String> zdiff(String... keys) {
return new JedisClusterCommand<Set<String>>(connectionHandler, maxAttempts) {
@Override
public Set<String> execute(Jedis connection) {
return connection.zdiff(keys);
}
}.run(keys.length, keys);
}

@Override
public Set<Tuple> zdiffWithScores(String... keys) {
return new JedisClusterCommand<Set<Tuple>>(connectionHandler, maxAttempts) {
@Override
public Set<Tuple> execute(Jedis connection) {
return connection.zdiffWithScores(keys);
}
}.run(keys.length, keys);
}

@Override
public Set<String> zrange(final String key, final long start, final long stop) {
return new JedisClusterCommand<Set<String>>(connectionHandler, maxAttempts) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,30 @@ public Response<String> unwatch() {
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<Set<byte[]>> zdiff(byte[]... keys) {
client.zdiff(keys);
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
}

@Override
public Response<Set<Tuple>> zdiffWithScores(byte[]... keys) {
client.zdiffWithScores(keys);
return getResponse(BuilderFactory.TUPLE_ZSET);
}

@Override
public Response<Set<String>> zdiff(String... keys) {
client.zdiff(keys);
return getResponse(BuilderFactory.STRING_ZSET);
}

@Override
public Response<Set<Tuple>> zdiffWithScores(String... keys) {
client.zdiffWithScores(keys);
return getResponse(BuilderFactory.TUPLE_ZSET);
}

@Override
public Response<Long> zinterstore(String dstkey, String... sets) {
client.zinterstore(dstkey, sets);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static enum Command implements ProtocolCommand {
SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET,
HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, HRANDFIELD, RPUSH, LPUSH, LLEN, LRANGE, LTRIM,
LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER,
SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM,
SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZDIFF, ZRANGE, ZREM,
ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZRANDMEMBER, ZCARD, ZSCORE, ZPOPMAX, ZPOPMIN, MULTI, DISCARD, EXEC,
WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE,
PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ default void setex(String key, int seconds, String value) {

void sdiffstore(String dstkey, String... keys);

void zdiff(String... keys);

void zdiffWithScores(String... keys);

void srandmember(String key);

void zadd(String key, double score, String member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.KeyedTuple;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
Expand Down Expand Up @@ -71,6 +72,10 @@ public interface MultiKeyBinaryCommands {

String unwatch();

Set<byte[]> zdiff(byte[]... keys);

Set<Tuple> zdiffWithScores(byte[]... keys);

Long zinterstore(byte[] dstkey, byte[]... sets);

Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.KeyedTuple;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
Expand Down Expand Up @@ -63,6 +64,10 @@ public interface MultiKeyBinaryJedisClusterCommands {

Long sunionstore(byte[] dstkey, byte[]... keys);

Set<byte[]> zdiff(byte[]... keys);

Set<Tuple> zdiffWithScores(byte[]... keys);

Long zinterstore(byte[] dstkey, byte[]... sets);

Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import redis.clients.jedis.Response;
import redis.clients.jedis.KeyedTuple;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.*;

Expand Down Expand Up @@ -67,6 +68,10 @@ public interface MultiKeyBinaryRedisPipeline {

Response<String> unwatch();

Response<Set<byte[]>> zdiff(byte[]... keys);

Response<Set<Tuple>> zdiffWithScores(byte[]... keys);

Response<Long> zinterstore(byte[] dstkey, byte[]... sets);

Response<Long> zinterstore(byte[] dstkey, ZParams params, byte[]... sets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
Expand Down Expand Up @@ -103,6 +104,10 @@ public interface MultiKeyCommands {

String unwatch();

Set<String> zdiff(String... keys);

Set<Tuple> zdiffWithScores(String... keys);

Long zinterstore(String dstkey, String... sets);

Long zinterstore(String dstkey, ZParams params, String... sets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.*;

Expand Down Expand Up @@ -68,6 +69,10 @@ public interface MultiKeyCommandsPipeline {

Response<String> unwatch();

Response<Set<String>> zdiff(String... keys);

Response<Set<Tuple>> zdiffWithScores(String... keys);

Response<Long> zinterstore(String dstkey, String... sets);

Response<Long> zinterstore(String dstkey, ZParams params, String... sets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
Expand Down Expand Up @@ -65,6 +66,10 @@ public interface MultiKeyJedisClusterCommands {

Long sunionstore(String dstkey, String... keys);

Set<String> zdiff(String... keys);

Set<Tuple> zdiffWithScores(String... keys);

Long zinterstore(String dstkey, String... sets);

Long zinterstore(String dstkey, ZParams params, String... sets);
Expand Down Expand Up @@ -115,7 +120,7 @@ List<Map.Entry<String, List<StreamEntry>>> xread(int count, long block,

List<Map.Entry<String, List<StreamEntry>>> xread(XReadParams xReadParams,
Map<String, StreamEntryID> streams);

/**
* XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...]
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,35 @@ public void bzpopmin() {
assertEquals(new KeyedTuple(bbar, bc, 0.1d), actual);
}

@Test
public void zdiff() {
jedis.zadd("foo", 1.0, "a");
jedis.zadd("foo", 2.0, "b");
jedis.zadd("bar", 1.0, "a");

assertEquals(0, jedis.zdiff("bar1", "bar2").size());
Set<String> actual = jedis.zdiff("foo", "bar");
assertEquals(1, actual.size());
assertEquals("b", actual.iterator().next());
Set<Tuple> actualWithScore = jedis.zdiffWithScores("foo", "bar");
assertEquals(1, actualWithScore.size());
assertEquals(new Tuple("b", 2.0d), actualWithScore.iterator().next());

// binary

jedis.zadd(bfoo, 1.0, ba);
jedis.zadd(bfoo, 2.0, bb);
jedis.zadd(bbar, 1.0, ba);

assertEquals(0, jedis.zdiff(bbar1, bbar2).size());
Set<byte[]> bactual = jedis.zdiff(bfoo, bbar);
assertEquals(1, bactual.size());
assertArrayEquals(bb, bactual.iterator().next());
actualWithScore = jedis.zdiffWithScores(bfoo, bbar);
assertEquals(1, actualWithScore.size());
assertEquals(new Tuple(bb, 2.0d), actualWithScore.iterator().next());
}

@Test
public void zrandmember() {
assertNull(jedis.zrandmember("foo"));
Expand Down