Skip to content

Commit

Permalink
Merge remote-tracking branch 'redis/master' into blocking-so-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Mar 18, 2021
2 parents 24e5ef6 + 43d8121 commit fb6fdae
Show file tree
Hide file tree
Showing 46 changed files with 1,636 additions and 185 deletions.
4 changes: 2 additions & 2 deletions .github/release-drafter-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name-template: 'Version $NEXT_PATCH_VERSION🌈'
tag-template: 'v$NEXT_PATCH_VERSION'
name-template: '$NEXT_PATCH_VERSION🌈'
tag-template: 'jedis-$NEXT_PATCH_VERSION'
categories:
- title: '🚀Features'
labels:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Or use it as a maven dependency:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand Down
142 changes: 119 additions & 23 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import static redis.clients.jedis.Protocol.toByteArray;
import static redis.clients.jedis.Protocol.Command.*;
import static redis.clients.jedis.Protocol.Keyword.ENCODING;
import static redis.clients.jedis.Protocol.Keyword.IDLETIME;
import static redis.clients.jedis.Protocol.Keyword.LEN;
import static redis.clients.jedis.Protocol.Keyword.LIMIT;
import static redis.clients.jedis.Protocol.Keyword.NO;
import static redis.clients.jedis.Protocol.Keyword.ONE;
import static redis.clients.jedis.Protocol.Keyword.REFCOUNT;
import static redis.clients.jedis.Protocol.Keyword.RESET;
import static redis.clients.jedis.Protocol.Keyword.STORE;
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
import static redis.clients.jedis.Protocol.Keyword.FREQ;
import static redis.clients.jedis.Protocol.Keyword.HELP;
import static redis.clients.jedis.Protocol.Command.EXISTS;
import static redis.clients.jedis.Protocol.Command.GET;
import static redis.clients.jedis.Protocol.Command.INCR;
import static redis.clients.jedis.Protocol.Command.KEYS;
import static redis.clients.jedis.Protocol.Command.PING;
import static redis.clients.jedis.Protocol.Command.PSUBSCRIBE;
import static redis.clients.jedis.Protocol.Command.PUNSUBSCRIBE;
import static redis.clients.jedis.Protocol.Command.SAVE;
import static redis.clients.jedis.Protocol.Command.SET;
import static redis.clients.jedis.Protocol.Command.SUBSCRIBE;
import static redis.clients.jedis.Protocol.Command.TIME;
import static redis.clients.jedis.Protocol.Command.UNSUBSCRIBE;
import static redis.clients.jedis.Protocol.Keyword.*;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -26,16 +27,8 @@
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
import redis.clients.jedis.params.ZIncrByParams;
import redis.clients.jedis.params.LPosParams;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.params.*;
import redis.clients.jedis.util.SafeEncoder;

public class BinaryClient extends Connection {
Expand Down Expand Up @@ -414,6 +407,18 @@ public void hgetAll(final byte[] key) {
sendCommand(HGETALL, key);
}

public void hrandfield(final byte[] key) {
sendCommand(HRANDFIELD, key);
}

public void hrandfield(final byte[] key, final long count) {
sendCommand(HRANDFIELD, key, toByteArray(count));
}

public void hrandfieldWithValues(final byte[] key, final long count) {
sendCommand(HRANDFIELD, key, toByteArray(count), WITHVALUES.getRaw());
}

public void rpush(final byte[] key, final byte[]... strings) {
sendCommand(RPUSH, joinParameters(key, strings));
}
Expand Down Expand Up @@ -1228,6 +1233,14 @@ public void clientId() {
sendCommand(CLIENT, Keyword.ID.getRaw());
}

public void clientUnblock(final long clientId, final UnblockType unblockType) {
if (unblockType == null) {
sendCommand(CLIENT, Keyword.UNBLOCK.getRaw(), toByteArray(clientId));
} else {
sendCommand(CLIENT, Keyword.UNBLOCK.getRaw(), toByteArray(clientId), unblockType.getRaw());
}
}

public void time() {
sendCommand(TIME);
}
Expand Down Expand Up @@ -1576,6 +1589,11 @@ public void xrevrange(final byte[] key, final byte[] end, final byte[] start, fi
sendCommand(XREVRANGE, key, end, start, Keyword.COUNT.getRaw(), toByteArray(count));
}

/**
* @deprecated This method will be removed due to bug regarding {@code block} param. Use
* {@link #xread(redis.clients.jedis.params.XReadParams, java.util.Map.Entry...)}.
*/
@Deprecated
public void xread(final int count, final long block, final Map<byte[], byte[]> streams) {
final byte[][] params = new byte[3 + streams.size() * 2 + (block > 0 ? 2 : 0)][];

Expand All @@ -1598,6 +1616,24 @@ public void xread(final int count, final long block, final Map<byte[], byte[]> s
sendCommand(XREAD, params);
}

public void xread(final XReadParams params, final Entry<byte[], byte[]>... streams) {
final byte[][] bparams = params.getByteParams();
final int paramLength = bparams.length;

final byte[][] args = new byte[paramLength + 1 + streams.length * 2][];
System.arraycopy(bparams, 0, args, 0, paramLength);

args[paramLength] = Keyword.STREAMS.raw;
int keyIndex = paramLength + 1;
int idsIndex = keyIndex + streams.length;
for (final Entry<byte[], byte[]> entry : streams) {
args[keyIndex++] = entry.getKey();
args[idsIndex++] = entry.getValue();
}

sendCommand(XREAD, args);
}

public void xack(final byte[] key, final byte[] group, final byte[]... ids) {
final byte[][] params = new byte[2 + ids.length][];
int index = 0;
Expand Down Expand Up @@ -1648,6 +1684,11 @@ public void xtrim(byte[] key, long maxLen, boolean approximateLength) {
}
}

/**
* @deprecated This method will be removed due to bug regarding {@code block} param. Use
* {@link #xreadGroup(byte..., byte..., redis.clients.jedis.params.XReadGroupParams, java.util.Map.Entry...)}.
*/
@Deprecated
public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block, boolean noAck,
Map<byte[], byte[]> streams) {

Expand Down Expand Up @@ -1690,6 +1731,30 @@ public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block,
sendCommand(XREADGROUP, params);
}

public void xreadGroup(byte[] groupname, byte[] consumer, final XReadGroupParams params,
final Entry<byte[], byte[]>... streams) {
final byte[][] bparams = params.getByteParams();
final int paramLength = bparams.length;

final byte[][] args = new byte[3 + paramLength + 1 + streams.length * 2][];
int index = 0;
args[index++] = Keyword.GROUP.raw;
args[index++] = groupname;
args[index++] = consumer;
System.arraycopy(bparams, 0, args, index, paramLength);
index += paramLength;

args[index++] = Keyword.STREAMS.raw;
int keyIndex = index;
int idsIndex = keyIndex + streams.length;
for (final Entry<byte[], byte[]> entry : streams) {
args[keyIndex++] = entry.getKey();
args[idsIndex++] = entry.getValue();
}

sendCommand(XREADGROUP, args);
}

public void xpending(byte[] key, byte[] groupname, byte[] start, byte[] end, int count,
byte[] consumername) {
if (consumername == null) {
Expand All @@ -1706,7 +1771,7 @@ public void xpendingSummary(final byte[] key, final byte[] groupname) {
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);
List<byte[]> arguments = new ArrayList<>(10 + ids.length);

arguments.add(key);
arguments.add(groupname);
Expand All @@ -1729,6 +1794,37 @@ public void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minId
sendCommand(XCLAIM, arguments.toArray(new byte[arguments.size()][]));
}

private void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime,
XClaimParams params, byte[][] ids, boolean justId) {
final byte[][] bparams = params.getByteParams();
final int paramLength = bparams.length;
final int idsLength = ids.length;
final byte[][] args = new byte[4 + paramLength + idsLength + (justId ? 1 : 0)][];
int index = 0;
args[index++] = key;
args[index++] = groupname;
args[index++] = consumername;
args[index++] = toByteArray(minIdleTime);
System.arraycopy(ids, 0, args, index, idsLength);
index += idsLength;
System.arraycopy(bparams, 0, args, index, paramLength);
index += paramLength;
if (justId) {
args[index++] = Keyword.JUSTID.getRaw();
}
sendCommand(XCLAIM, args);
}

public void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime,
XClaimParams params, byte[]... ids) {
xclaim(key, groupname, consumername, minIdleTime, params, ids, false);
}

public void xclaimJustId(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime,
XClaimParams params, byte[]... ids) {
xclaim(key, groupname, consumername, minIdleTime, params, ids, true);
}

public void xinfoStream(byte[] key) {
sendCommand(XINFO, Keyword.STREAM.getRaw(), key);
}
Expand Down
Loading

0 comments on commit fb6fdae

Please sign in to comment.