Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support INCR argument to ZADD command #2415

Merged
merged 4 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -566,6 +566,10 @@ public void zadd(final byte[] key, final Map<byte[], Double> scoreMembers, final
sendCommand(ZADD, params.getByteParams(key, argsArray));
}

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));
}

public void zrange(final byte[] key, final long start, final long stop) {
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(stop));
}
Expand Down
55 changes: 31 additions & 24 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1840,14 +1840,14 @@ public Long sunionstore(final byte[] dstkey, final byte[]... keys) {
* Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
* <p>
* <b>Example:</b>
*
*
* <pre>
* key1 = [x, a, b, c]
* key2 = [c]
* key3 = [a, d]
* SDIFF key1,key2,key3 =&gt; [x, b]
* </pre>
*
*
* Non existing keys are considered like empty sets.
* <p>
* <b>Time complexity:</b>
Expand Down Expand Up @@ -1947,6 +1947,13 @@ public Long zadd(final byte[] key, final Map<byte[], Double> scoreMembers, final
return client.getIntegerReply();
}

@Override
public Double zaddIncr(final byte[] key, final double score, final byte[] member, final ZAddParams params) {
checkIsInMultiOrPipeline();
client.zaddIncr(key, score, member, params);
return BuilderFactory.DOUBLE.build(client.getOne());
}

@Override
public Set<byte[]> zrange(final byte[] key, final long start, final long stop) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -2205,65 +2212,65 @@ public List<byte[]> sort(final byte[] key) {
* <b>examples:</b>
* <p>
* Given are the following sets and key/values:
*
*
* <pre>
* x = [1, 2, 3]
* y = [a, b, c]
*
*
* k1 = z
* k2 = y
* k3 = x
*
*
* w1 = 9
* w2 = 8
* w3 = 7
* </pre>
*
*
* Sort Order:
*
*
* <pre>
* sort(x) or sort(x, sp.asc())
* -&gt; [1, 2, 3]
*
*
* sort(x, sp.desc())
* -&gt; [3, 2, 1]
*
*
* sort(y)
* -&gt; [c, a, b]
*
*
* sort(y, sp.alpha())
* -&gt; [a, b, c]
*
*
* sort(y, sp.alpha().desc())
* -&gt; [c, a, b]
* </pre>
*
*
* Limit (e.g. for Pagination):
*
*
* <pre>
* sort(x, sp.limit(0, 2))
* -&gt; [1, 2]
*
*
* sort(y, sp.alpha().desc().limit(1, 2))
* -&gt; [b, a]
* </pre>
*
*
* Sorting by external keys:
*
*
* <pre>
* sort(x, sb.by(w*))
* -&gt; [3, 2, 1]
*
*
* sort(x, sb.by(w*).desc())
* -&gt; [1, 2, 3]
* </pre>
*
*
* Getting external keys:
*
*
* <pre>
* sort(x, sp.by(w*).get(k*))
* -&gt; [x, y, z]
*
*
* sort(x, sp.by(w*).get(#).get(k*))
* -&gt; [3, x, 2, y, 1, z]
* </pre>
Expand Down Expand Up @@ -3198,7 +3205,7 @@ public String shutdown() {
* <b>Format of the returned String:</b>
* <p>
* All the fields are in the form field:value
*
*
* <pre>
* edis_version:0.07
* connected_clients:1
Expand All @@ -3211,7 +3218,7 @@ public String shutdown() {
* uptime_in_seconds:25
* uptime_in_days:0
* </pre>
*
*
* <b>Notes</b>
* <p>
* used_memory is returned in bytes, and is the total number of bytes allocated by the program
Expand Down Expand Up @@ -3293,7 +3300,7 @@ public String slaveofNoOne() {
* are reported as a list of key-value pairs.
* <p>
* <b>Example:</b>
*
*
* <pre>
* $ redis-cli config get '*'
* 1. "dbfilename"
Expand All @@ -3308,7 +3315,7 @@ public String slaveofNoOne() {
* 10. "everysec"
* 11. "save"
* 12. "3600 1 300 100 60 10000"
*
*
* $ redis-cli config get 'm*'
* 1. "masterauth"
* 2. (nil)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ public Long zadd(final byte[] key, final Map<byte[], Double> scoreMembers, final
return j.zadd(key, scoreMembers, params);
}

@Override
public Double zaddIncr(final byte[] key, final double score, final byte[] member, final ZAddParams params) {
Jedis j = getShard(key);
return j.zaddIncr(key, score, member, params);
}

@Override
public Set<byte[]> zrange(final byte[] key, final long start, final long stop) {
Jedis j = getShard(key);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ public void zadd(final String key, final Map<String, Double> scoreMembers, final
zadd(SafeEncoder.encode(key), binaryScoreMembers, params);
}

@Override
public void zaddIncr(final String key, final double score, final String member, final ZAddParams params) {
zaddIncr(SafeEncoder.encode(key), score, SafeEncoder.encode(member), params);
}

@Override
public void zrange(final String key, final long start, final long stop) {
zrange(SafeEncoder.encode(key), start, stop);
Expand Down Expand Up @@ -1399,14 +1404,14 @@ public void xreadGroup(String groupname, String consumer, int count, long block,
for (final Entry<String, StreamEntryID> entry : streams) {
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()==null ? ">" : entry.getValue().toString()));
}
xreadGroup(SafeEncoder.encode(groupname), SafeEncoder.encode(consumer), count, block, noAck, bhash);
xreadGroup(SafeEncoder.encode(groupname), SafeEncoder.encode(consumer), count, block, noAck, bhash);
}

@Override
public void xpending(String key, String groupname, StreamEntryID start, StreamEntryID end,
int count, String consumername) {
xpending(SafeEncoder.encode(key), SafeEncoder.encode(groupname), SafeEncoder.encode(start==null ? "-" : start.toString()),
SafeEncoder.encode(end==null ? "+" : end.toString()), count, consumername == null? null : SafeEncoder.encode(consumername));
SafeEncoder.encode(end==null ? "+" : end.toString()), count, consumername == null? null : SafeEncoder.encode(consumername));
}

@Override
Expand All @@ -1417,7 +1422,7 @@ public void xclaim(String key, String group, String consumername, long minIdleTi
for (int i = 0; i < ids.length; i++) {
bids[i] = SafeEncoder.encode(ids[i].toString());
}
xclaim(SafeEncoder.encode(key), SafeEncoder.encode(group), SafeEncoder.encode(consumername), minIdleTime, newIdleTime, retries, force, bids);
xclaim(SafeEncoder.encode(key), SafeEncoder.encode(group), SafeEncoder.encode(consumername), minIdleTime, newIdleTime, retries, force, bids);
}

@Override
Expand Down
53 changes: 30 additions & 23 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1523,14 +1523,14 @@ public Long sunionstore(final String dstkey, final String... keys) {
* Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
* <p>
* <b>Example:</b>
*
*
* <pre>
* key1 = [x, a, b, c]
* key2 = [c]
* key3 = [a, d]
* SDIFF key1,key2,key3 =&gt; [x, b]
* </pre>
*
*
* Non existing keys are considered like empty sets.
* <p>
* <b>Time complexity:</b>
Expand Down Expand Up @@ -1630,6 +1630,13 @@ public Long zadd(final String key, final Map<String, Double> scoreMembers, final
return client.getIntegerReply();
}

@Override
public Double zaddIncr(final String key, final double score, final String member, final ZAddParams params) {
checkIsInMultiOrPipeline();
client.zaddIncr(key, score, member, params);
return BuilderFactory.DOUBLE.build(client.getOne());
}

@Override
public Set<String> zrange(final String key, final long start, final long stop) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -1866,65 +1873,65 @@ public List<String> sort(final String key) {
* <b>examples:</b>
* <p>
* Given are the following sets and key/values:
*
*
* <pre>
* x = [1, 2, 3]
* y = [a, b, c]
*
*
* k1 = z
* k2 = y
* k3 = x
*
*
* w1 = 9
* w2 = 8
* w3 = 7
* </pre>
*
*
* Sort Order:
*
*
* <pre>
* sort(x) or sort(x, sp.asc())
* -&gt; [1, 2, 3]
*
*
* sort(x, sp.desc())
* -&gt; [3, 2, 1]
*
*
* sort(y)
* -&gt; [c, a, b]
*
*
* sort(y, sp.alpha())
* -&gt; [a, b, c]
*
*
* sort(y, sp.alpha().desc())
* -&gt; [c, a, b]
* </pre>
*
*
* Limit (e.g. for Pagination):
*
*
* <pre>
* sort(x, sp.limit(0, 2))
* -&gt; [1, 2]
*
*
* sort(y, sp.alpha().desc().limit(1, 2))
* -&gt; [b, a]
* </pre>
*
*
* Sorting by external keys:
*
*
* <pre>
* sort(x, sb.by(w*))
* -&gt; [3, 2, 1]
*
*
* sort(x, sb.by(w*).desc())
* -&gt; [1, 2, 3]
* </pre>
*
*
* Getting external keys:
*
*
* <pre>
* sort(x, sp.by(w*).get(k*))
* -&gt; [x, y, z]
*
*
* sort(x, sp.by(w*).get(#).get(k*))
* -&gt; [3, x, 2, y, 1, z]
* </pre>
Expand Down Expand Up @@ -2866,7 +2873,7 @@ public Long bitpos(final String key, final boolean value, final BitPosParams par
* are reported as a list of key-value pairs.
* <p>
* <b>Example:</b>
*
*
* <pre>
* $ redis-cli config get '*'
* 1. "dbfilename"
Expand All @@ -2881,7 +2888,7 @@ public Long bitpos(final String key, final boolean value, final BitPosParams par
* 10. "everysec"
* 11. "save"
* 12. "3600 1 300 100 60 10000"
*
*
* $ redis-cli config get 'm*'
* 1. "masterauth"
* 2. (nil)
Expand Down Expand Up @@ -3131,7 +3138,7 @@ public Long bitop(final BitOP op, final String destKey, final String... srcKeys)
* 22) "2"
* 23) "quorum"
* 24) "2"
*
*
* </pre>
* @return
*/
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 @@ -282,7 +282,7 @@ public static enum Keyword {
GETNAME, SETNAME, LIST, MATCH, COUNT, PING, PONG, UNLOAD, REPLACE, KEYS, PAUSE, DOCTOR, BLOCK,
NOACK, STREAMS, KEY, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, ID, IDLE,
TIME, RETRYCOUNT, FORCE, USAGE, SAMPLES, STREAM, GROUPS, CONSUMERS, HELP, FREQ, SETUSER,
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG;
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG, INCR;

/**
* @deprecated This will be private in future. Use {@link #getRaw()}.
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ public Long zadd(final String key, final Map<String, Double> scoreMembers, final
return j.zadd(key, scoreMembers, params);
}

@Override
public Double zaddIncr(final String key, final double score, final String member, final ZAddParams params) {
Jedis j = getShard(key);
return j.zaddIncr(key, score, member, params);
}

@Override
public Set<String> zrange(final String key, final long start, final long stop) {
Jedis j = getShard(key);
Expand Down
Loading