Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ public void zaddIncr(final byte[] key, final double score, final byte[] member,
sendCommand(ZADD, params.getByteParams(key, INCR.getRaw(), toByteArray(score), member));
}

public void zdiffStore(final byte[] dstkey, final byte[]... keys) {
sendCommand(ZDIFFSTORE, joinParameters(dstkey, toByteArray(keys.length), keys));
}

public void zrange(final byte[] key, final long start, final long stop) {
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(stop));
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,13 @@ public Set<Tuple> zdiffWithScores(final byte[]... keys) {
return getTupledSet();
}

@Override
public Long zdiffStore(final byte[] dstkey, final byte[]... keys) {
checkIsInMultiOrPipeline();
client.zdiffStore(dstkey, keys);
return client.getIntegerReply();
}

/**
* 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
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,17 @@ public Set<Tuple> execute(Jedis connection) {
}.runBinary(keys.length, keys);
}

@Override
public Long zdiffStore(final byte[] dstkey, final byte[]... keys) {
byte[][] wholeKeys = KeyMergeUtil.merge(dstkey, keys);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.zdiffStore(dstkey, keys);
}
}.runBinary(wholeKeys.length, wholeKeys);
}

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

@Override
public void zdiffStore(final String dstkey, final String... keys) {
zdiffStore(SafeEncoder.encode(dstkey), SafeEncoder.encodeMany(keys));
}

@Override
public void zrangeByScore(final String key, final double min, final double max) {
zrangeByScore(SafeEncoder.encode(key), toByteArray(min), toByteArray(max));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,13 @@ public Set<Tuple> zdiffWithScores(String... keys) {
return getTupledSet();
}

@Override
public Long zdiffStore(final String dstkey, final String... keys) {
checkIsInMultiOrPipeline();
client.zdiffStore(dstkey, keys);
return BuilderFactory.LONG.build(client.getOne());
}

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

@Override
public Long zdiffStore(final String dstkey, final String... keys) {
String[] wholeKeys = KeyMergeUtil.merge(dstkey, keys);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.zdiffStore(dstkey, keys);
}
}.run(wholeKeys.length, wholeKeys);
}

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

@Override
public Response<Long> zdiffStore(final byte[] dstkey, final byte[]... keys) {
client.zdiffStore(dstkey, keys);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> zdiffStore(final String dstkey, final String... keys) {
client.zdiffStore(dstkey, keys);
return getResponse(BuilderFactory.LONG);
}

@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, ZDIFF, ZRANGE, ZREM,
SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZDIFF, ZDIFFSTORE, 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
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ default void setex(String key, int seconds, String value) {

void zaddIncr(String key, double score, String member, ZAddParams params);

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

void zrange(String key, long start, long stop);

void zrem(String key, String... members);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public interface MultiKeyBinaryCommands {

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

Long zdiffStore(byte[] dstkey, 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 @@ -68,6 +68,8 @@ public interface MultiKeyBinaryJedisClusterCommands {

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

Long zdiffStore(byte[] dstkey, 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 @@ -72,6 +72,8 @@ public interface MultiKeyBinaryRedisPipeline {

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

Response<Long> zdiffStore(byte[] dstkey, 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 @@ -108,6 +108,8 @@ public interface MultiKeyCommands {

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

Long zdiffStore(String dstkey, 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 @@ -73,6 +73,8 @@ public interface MultiKeyCommandsPipeline {

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

Response<Long> zdiffStore(String dstkey, 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 @@ -70,6 +70,8 @@ public interface MultiKeyJedisClusterCommands {

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

Long zdiffStore(String dstkey, 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 @@ -1469,6 +1469,28 @@ public void zdiff() {
assertEquals(Collections.singleton(new Tuple(bb, 2.0d)), jedis.zdiffWithScores(bfoo, bbar));
}

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

assertEquals(0, jedis.zdiffStore("bar3", "bar1", "bar2").longValue());
assertEquals(1, jedis.zdiffStore("bar3", "foo", "bar").longValue());
assertEquals(Collections.singleton("b"), jedis.zrange("bar3", 0, -1));

// binary

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

assertEquals(0, jedis.zdiffStore(bbar3, bbar1, bbar2).longValue());
assertEquals(1, jedis.zdiffStore(bbar3, bfoo, bbar).longValue());
Set<byte[]> bactual = jedis.zrange(bbar3, 0, -1);
assertArrayEquals(bb, bactual.iterator().next());
}

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