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 1 commit
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
68 changes: 36 additions & 32 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public void setPassword(final String password) {
this.password = password;
}


/**
* This method should be called only after a successful SELECT command.
* @param db
* @param db
*/
public void setDb(int db) {
this.db = db;
Expand Down Expand Up @@ -190,7 +190,7 @@ public void set(final byte[] key, final byte[] value, final SetParams params) {
public void get(final byte[] key) {
sendCommand(GET, key);
}

public void getDel(final byte[] key) {
sendCommand(GETDEL, key);
}
Expand Down Expand Up @@ -563,6 +563,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.incr().getByteParams(key, toByteArray(score), member));
}

public void zrange(final byte[] key, final long start, final long stop) {
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(stop));
}
Expand Down Expand Up @@ -1155,11 +1159,11 @@ public void srandmember(final byte[] key, final int count) {
public void memoryDoctor() {
sendCommand(MEMORY, Keyword.DOCTOR.getRaw());
}

public void memoryUsage(final byte[] key) {
sendCommand(MEMORY, Keyword.USAGE.getRaw(), key);
}

public void memoryUsage(final byte[] key, final int samples) {
sendCommand(MEMORY, Keyword.USAGE.getRaw(), key, Keyword.SAMPLES.getRaw(), toByteArray(samples));
}
Expand Down Expand Up @@ -1464,17 +1468,17 @@ public void bitfieldReadonly(final byte[] key, final byte[]... arguments) {
public void hstrlen(final byte[] key, final byte[] field) {
sendCommand(HSTRLEN, key, field);
}

public void xadd(final byte[] key, final byte[] id, final Map<byte[], byte[]> hash, long maxLen, boolean approximateLength) {
int maxLexArgs = 0;
if(maxLen < Long.MAX_VALUE) { // optional arguments
if(approximateLength) {
maxLexArgs = 3; // e.g. MAXLEN ~ 1000
maxLexArgs = 3; // e.g. MAXLEN ~ 1000
} else {
maxLexArgs = 2; // e.g. MAXLEN 1000
}
}

final byte[][] params = new byte[2 + maxLexArgs + hash.size() * 2][];
int index = 0;
params[index++] = key;
Expand All @@ -1485,15 +1489,15 @@ public void xadd(final byte[] key, final byte[] id, final Map<byte[], byte[]> ha
}
params[index++] = toByteArray(maxLen);
}

params[index++] = id;
for (final Entry<byte[], byte[]> entry : hash.entrySet()) {
params[index++] = entry.getKey();
params[index++] = entry.getValue();
}
sendCommand(XADD, params);
}

public void xlen(final byte[] key) {
sendCommand(XLEN, key);
}
Expand Down Expand Up @@ -1524,18 +1528,18 @@ public void xread(final int count, final long block, final Map<byte[], byte[]> s
params[streamsIndex++] = Keyword.BLOCK.getRaw();
params[streamsIndex++] = toByteArray(block);
}

params[streamsIndex++] = Keyword.STREAMS.getRaw();
int idsIndex = streamsIndex + streams.size();

for (final Entry<byte[], byte[]> entry : streams.entrySet()) {
params[streamsIndex++] = entry.getKey();
params[idsIndex++] = entry.getValue();
}

sendCommand(XREAD, params);
}

public void xack(final byte[] key, final byte[] group, final byte[]... ids) {
final byte[][] params = new byte[2 + ids.length][];
int index = 0;
Expand All @@ -1546,27 +1550,27 @@ public void xack(final byte[] key, final byte[] group, final byte[]... ids) {
}
sendCommand(XACK, params);
}

public void xgroupCreate(final byte[] key, final byte[] groupname, final byte[] id, boolean makeStream) {
if(makeStream) {
sendCommand(XGROUP, Keyword.CREATE.getRaw(), key, groupname, id, Keyword.MKSTREAM.getRaw());
sendCommand(XGROUP, Keyword.CREATE.getRaw(), key, groupname, id, Keyword.MKSTREAM.getRaw());
} else {
sendCommand(XGROUP, Keyword.CREATE.getRaw(), key, groupname, id);
sendCommand(XGROUP, Keyword.CREATE.getRaw(), key, groupname, id);
}
}

public void xgroupSetID(final byte[] key, final byte[] groupname, final byte[] id) {
sendCommand(XGROUP, Keyword.SETID.getRaw(), key, groupname, id);
sendCommand(XGROUP, Keyword.SETID.getRaw(), key, groupname, id);
}

public void xgroupDestroy(final byte[] key, final byte[] groupname) {
sendCommand(XGROUP, Keyword.DESTROY.getRaw(), key, groupname);
sendCommand(XGROUP, Keyword.DESTROY.getRaw(), key, groupname);
}

public void xgroupDelConsumer(final byte[] key, final byte[] groupname, final byte[] consumerName) {
sendCommand(XGROUP, Keyword.DELCONSUMER.getRaw(), key, groupname, consumerName);
sendCommand(XGROUP, Keyword.DELCONSUMER.getRaw(), key, groupname, consumerName);
}

public void xdel(final byte[] key, final byte[]... ids) {
final byte[][] params = new byte[1 + ids.length][];
int index = 0;
Expand All @@ -1576,17 +1580,17 @@ public void xdel(final byte[] key, final byte[]... ids) {
}
sendCommand(XDEL, params);
}

public void xtrim(byte[] key, long maxLen, boolean approximateLength) {
if(approximateLength) {
sendCommand(XTRIM, key, Keyword.MAXLEN.getRaw(), Protocol.BYTES_TILDE ,toByteArray(maxLen));
} else {
sendCommand(XTRIM, key, Keyword.MAXLEN.getRaw(), toByteArray(maxLen));
}
}

public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block, boolean noAck, Map<byte[], byte[]> streams) {

int optional = 0;
if(count>0) {
optional += 2;
Expand All @@ -1597,8 +1601,8 @@ public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block,
if(noAck) {
optional += 1;
}


final byte[][] params = new byte[4 + optional + streams.size() * 2][];

int streamsIndex = 0;
Expand All @@ -1617,17 +1621,17 @@ public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block,
params[streamsIndex++] = Keyword.NOACK.getRaw();
}
params[streamsIndex++] = Keyword.STREAMS.getRaw();

int idsIndex = streamsIndex + streams.size();
for (final Entry<byte[], byte[]> entry : streams.entrySet()) {
params[streamsIndex++] = entry.getKey();
params[idsIndex++] = entry.getValue();
}

sendCommand(XREADGROUP, params);
}


public void xpending(byte[] key, byte[] groupname, byte[] start, byte[] end, int count, byte[] consumername) {
if(consumername == null) {
sendCommand(XPENDING, key, groupname, start, end, toByteArray(count));
Expand All @@ -1637,14 +1641,14 @@ public void xpending(byte[] key, byte[] groupname, byte[] start, byte[] end, int
}

public void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime, long newIdleTime, int retries, boolean force, byte[][] ids) {

ArrayList<byte[]> arguments = new ArrayList<>(10 + ids.length);

arguments.add(key);
arguments.add(groupname);
arguments.add(consumername);
arguments.add(toByteArray(minIdleTime));

Collections.addAll(arguments, ids);

if(newIdleTime > 0) {
Expand All @@ -1653,10 +1657,10 @@ public void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minId
}
if(retries > 0) {
arguments.add(Keyword.RETRYCOUNT.getRaw());
arguments.add(toByteArray(retries));
arguments.add(toByteArray(retries));
}
if(force) {
arguments.add(Keyword.FORCE.getRaw());
arguments.add(Keyword.FORCE.getRaw());
}
sendCommand(XCLAIM, arguments.toArray(new byte[arguments.size()][]));
}
Expand Down
Loading