Skip to content

Commit

Permalink
Merge branch 'master' into 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Mar 6, 2024
2 parents e66f498 + 25acc8d commit c02e5be
Show file tree
Hide file tree
Showing 32 changed files with 766 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/doctests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags-ignore:
- '*'
branches:
- 'emb-examples'
pull_request:
workflow_dispatch:

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
<version>20240205</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -100,7 +100,7 @@
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-core</artifactId>
<version>2.8.3</version>
<version>2.9.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ protected AbstractTransaction() {
super(new CommandObjects());
}

protected AbstractTransaction(CommandObjects commandObjects) {
super(commandObjects);
}

public abstract void multi();

/**
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,53 @@ public Map<String, CommandInfo> build(Object data) {
}
};

public static final Builder<Map<String, LatencyLatestInfo>> LATENCY_LATEST_RESPONSE = new Builder<Map<String, LatencyLatestInfo>>() {
@Override
public Map<String, LatencyLatestInfo> build(Object data) {
if (data == null) {
return null;
}

List<Object> rawList = (List<Object>) data;
Map<String, LatencyLatestInfo> map = new HashMap<>(rawList.size());

for (Object rawLatencyLatestInfo : rawList) {
if (rawLatencyLatestInfo == null) {
continue;
}

LatencyLatestInfo latestInfo = LatencyLatestInfo.LATENCY_LATEST_BUILDER.build(rawLatencyLatestInfo);
String name = latestInfo.getCommand();
map.put(name, latestInfo);
}

return map;
}
};

public static final Builder<List<LatencyHistoryInfo>> LATENCY_HISTORY_RESPONSE = new Builder<List<LatencyHistoryInfo>>() {
@Override
public List<LatencyHistoryInfo> build(Object data) {
if (data == null) {
return null;
}

List<Object> rawList = (List<Object>) data;
List<LatencyHistoryInfo> response = new ArrayList<>(rawList.size());

for (Object rawLatencyHistoryInfo : rawList) {
if (rawLatencyHistoryInfo == null) {
continue;
}

LatencyHistoryInfo historyInfo = LatencyHistoryInfo.LATENCY_HISTORY_BUILDER.build(rawLatencyHistoryInfo);
response.add(historyInfo);
}

return response;
}
};

private static final Builder<List<List<Long>>> CLUSTER_SHARD_SLOTS_RANGES = new Builder<List<List<Long>>>() {

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,10 @@ public final CommandObject<ScanResult<Map.Entry<String, String>>> hscan(String k
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params), BuilderFactory.HSCAN_RESPONSE);
}

public final CommandObject<ScanResult<String>> hscanNoValues(String key, String cursor, ScanParams params) {
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params).add(NOVALUES), BuilderFactory.SCAN_RESPONSE);
}

public final CommandObject<Long> hstrlen(String key, String field) {
return new CommandObject<>(commandArguments(HSTRLEN).key(key).add(field), BuilderFactory.LONG);
}
Expand All @@ -1136,6 +1140,10 @@ public final CommandObject<ScanResult<Map.Entry<byte[], byte[]>>> hscan(byte[] k
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params), BuilderFactory.HSCAN_BINARY_RESPONSE);
}

public final CommandObject<ScanResult<byte[]>> hscanNoValues(byte[] key, byte[] cursor, ScanParams params) {
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params).add(NOVALUES), BuilderFactory.SCAN_BINARY_RESPONSE);
}

public final CommandObject<Long> hstrlen(byte[] key, byte[] field) {
return new CommandObject<>(commandArguments(HSTRLEN).key(key).add(field), BuilderFactory.LONG);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/ConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean validateObject(PooledObject<Connection> pooledConnection) {
// check HostAndPort ??
return jedis.isConnected() && jedis.ping();
} catch (final Exception e) {
logger.error("Error while validating pooled Connection object.", e);
logger.warn("Error while validating pooled Connection object.", e);
return false;
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.Arrays;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
Expand Down Expand Up @@ -4412,18 +4413,19 @@ public ScanResult<byte[]> scan(final byte[] cursor, final ScanParams params, fin
return connection.executeCommand(commandObjects.scan(cursor, params, type));
}

@Override
public ScanResult<Map.Entry<byte[], byte[]>> hscan(final byte[] key, final byte[] cursor) {
return hscan(key, cursor, new ScanParams());
}

@Override
public ScanResult<Map.Entry<byte[], byte[]>> hscan(final byte[] key, final byte[] cursor,
final ScanParams params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public ScanResult<byte[]> hscanNoValues(final byte[] key, final byte[] cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public ScanResult<byte[]> sscan(final byte[] key, final byte[] cursor) {
return sscan(key, cursor, new ScanParams());
Expand Down Expand Up @@ -8616,6 +8618,12 @@ public ScanResult<Map.Entry<String, String>> hscan(final String key, final Strin
return connection.executeCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public ScanResult<String> hscanNoValues(final String key, final String cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public ScanResult<String> sscan(final String key, final String cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -9280,6 +9288,26 @@ public String latencyDoctor() {
return connection.getBulkReply();
}

public Map<String, LatencyLatestInfo> latencyLatest() {
checkIsInMultiOrPipeline();
connection.sendCommand(LATENCY, LATEST);
return BuilderFactory.LATENCY_LATEST_RESPONSE.build(connection.getOne());
}

public List<LatencyHistoryInfo> latencyHistory(LatencyEvent event) {
checkIsInMultiOrPipeline();
connection.sendCommand(new CommandArguments(LATENCY).add(HISTORY).add(event));
return BuilderFactory.LATENCY_HISTORY_RESPONSE.build(connection.getOne());
}

public long latencyReset(LatencyEvent... events) {
checkIsInMultiOrPipeline();
CommandArguments arguments = new CommandArguments(LATENCY).add(Keyword.RESET);
Arrays.stream(events).forEach(arguments::add);
connection.sendCommand(arguments);
return connection.getIntegerReply();
}

@Override
public StreamEntryID xadd(final String key, final StreamEntryID id, final Map<String, String> hash) {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/JedisFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public boolean validateObject(PooledObject<Jedis> pooledJedis) {
&& jedis.getConnection().isConnected()
&& jedis.ping().equals("PONG");
} catch (final Exception e) {
logger.error("Error while validating pooled Jedis object.", e);
logger.warn("Error while validating pooled Jedis object.", e);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/JedisPubSubBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void process() {
} else {
throw new JedisException("Unknown message type: " + reply);
}
} while (isSubscribed());
} while (!Thread.currentThread().isInterrupted() && isSubscribed());

// /* Invalidate instance since this thread is no longer listening */
// this.client = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void process() {
} else {
throw new JedisException("Unknown message type: " + reply);
}
} while (isSubscribed());
} while (!Thread.currentThread().isInterrupted() && isSubscribed());

// /* Invalidate instance since this thread is no longer listening */
// this.client = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public final class MultiClusterClientConfig {
private static final float CIRCUIT_BREAKER_SLOW_CALL_RATE_THRESHOLD_DEFAULT = 100.0f; // measured as percentage
private static final List<Class> CIRCUIT_BREAKER_INCLUDED_EXCEPTIONS_DEFAULT = Arrays.asList(JedisConnectionException.class);

private static final List<Class<? extends Throwable>> FALLBACK_EXCEPTIONS_DEFAULT =
Arrays.asList(CallNotPermittedException.class, JedisConnectionException.class);
private static final List<Class<? extends Throwable>> FALLBACK_EXCEPTIONS_DEFAULT = Arrays.asList(CallNotPermittedException.class);

private final ClusterConfig[] clusterConfigs;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ protected final <T> Response<T> appendCommand(CommandObject<T> commandObject) {
queue = pipelinedResponses.get(nodeKey);
connection = connections.get(nodeKey);
} else {
pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>());
queue = pipelinedResponses.get(nodeKey);

Connection newOne = getConnection(nodeKey);
connections.putIfAbsent(nodeKey, newOne);
connection = connections.get(nodeKey);
if (connection != newOne) {
log.debug("Duplicate connection to {}, closing it.", nodeKey);
IOUtils.closeQuietly(newOne);
}

pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>());
queue = pipelinedResponses.get(nodeKey);
}

connection.sendCommand(commandObject.getArguments());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/PipeliningBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ public Response<ScanResult<Map.Entry<String, String>>> hscan(String key, String
return appendCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public Response<ScanResult<String>> hscanNoValues(String key, String cursor, ScanParams params) {
return appendCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public Response<Long> hstrlen(String key, String field) {
return appendCommand(commandObjects.hstrlen(key, field));
Expand Down Expand Up @@ -1972,6 +1977,11 @@ public Response<ScanResult<Map.Entry<byte[], byte[]>>> hscan(byte[] key, byte[]
return appendCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public Response<ScanResult<byte[]>> hscanNoValues(byte[] key, byte[] cursor, ScanParams params) {
return appendCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public Response<Long> hstrlen(byte[] key, byte[] field) {
return appendCommand(commandObjects.hstrlen(key, field));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ public static enum Keyword implements Rawable {
REV, WITHCOORD, WITHDIST, WITHHASH, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE,
STOREDIST, TO, FORCE, TIMEOUT, DB, UNLOAD, ABORT, IDX, MINMATCHLEN, WITHMATCHLEN, FULL,
DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, GETKEYS, GETKEYSANDFLAGS, DOCS, FILTERBY, DUMP,
MODULE, ACLCAT, PATTERN, DOCTOR, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS, RANK,
MODULE, ACLCAT, PATTERN, DOCTOR, LATEST, HISTORY, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS, RANK,
NOW, VERSION, ADDR, SKIPME, USER, LADDR,
CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB;
CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NOVALUES;

private final byte[] raw;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/TransactionBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public abstract class TransactionBase extends AbstractTransaction {
protected TransactionBase() {
super();
}

protected TransactionBase(CommandObjects commandObjects) {
super(commandObjects);
}
}
14 changes: 12 additions & 2 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,11 @@ public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, Sc
return executeCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public ScanResult<String> hscanNoValues(String key, String cursor, ScanParams params) {
return executeCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public long hstrlen(String key, String field) {
return checkAndClientSideCacheCommand(commandObjects.hstrlen(key, field), key);
Expand All @@ -1609,6 +1614,11 @@ public ScanResult<Map.Entry<byte[], byte[]>> hscan(byte[] key, byte[] cursor, Sc
return executeCommand(commandObjects.hscan(key, cursor, params));
}

@Override
public ScanResult<byte[]> hscanNoValues(byte[] key, byte[] cursor, ScanParams params) {
return executeCommand(commandObjects.hscanNoValues(key, cursor, params));
}

@Override
public long hstrlen(byte[] key, byte[] field) {
return checkAndClientSideCacheCommand(commandObjects.hstrlen(key, field), key);
Expand Down Expand Up @@ -4874,7 +4884,7 @@ public PipelineBase pipelined() {
if (provider == null) {
throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass());
} else if (provider instanceof MultiClusterPooledConnectionProvider) {
return new MultiClusterPipeline((MultiClusterPooledConnectionProvider) provider);
return new MultiClusterPipeline((MultiClusterPooledConnectionProvider) provider, commandObjects);
} else {
return new Pipeline(provider.getConnection(), true);
}
Expand All @@ -4884,7 +4894,7 @@ public AbstractTransaction multi() {
if (provider == null) {
throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass());
} else if (provider instanceof MultiClusterPooledConnectionProvider) {
return new MultiClusterTransaction((MultiClusterPooledConnectionProvider) provider);
return new MultiClusterTransaction((MultiClusterPooledConnectionProvider) provider, true, commandObjects);
} else {
return new Transaction(provider.getConnection(), true, true);
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/redis/clients/jedis/args/LatencyEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package redis.clients.jedis.args;

import redis.clients.jedis.util.SafeEncoder;

public enum LatencyEvent implements Rawable {

ACTIVE_DEFRAG_CYCLE("active-defrag-cycle"), AOF_FSYNC_ALWAYS("aof-fsync-always"), AOF_STAT("aof-stat"),
AOF_REWRITE_DIFF_WRITE("aof-rewrite-diff-write"), AOF_RENAME("aof-rename"), AOF_WRITE("aof-write"),
AOF_WRITE_ACTIVE_CHILD("aof-write-active-child"), AOF_WRITE_ALONE("aof-write-alone"),
AOF_WRITE_PENDING_FSYNC("aof-write-pending-fsync"), COMMAND("command"), EXPIRE_CYCLE("expire-cycle"),
EVICTION_CYCLE("eviction-cycle"), EVICTION_DEL("eviction-del"), FAST_COMMAND("fast-command"),
FORK("fork"), RDB_UNLINK_TEMP_FILE("rdb-unlink-temp-file");

private final byte[] raw;

private LatencyEvent(String s) {
raw = SafeEncoder.encode(s);
}

@Override
public byte[] getRaw() {
return raw;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ default ScanResult<Map.Entry<byte[], byte[]>> hscan(byte[] key, byte[] cursor) {

ScanResult<Map.Entry<byte[], byte[]>> hscan(byte[] key, byte[] cursor, ScanParams params);

default ScanResult<byte[]> hscanNoValues(byte[] key, byte[] cursor) {
return hscanNoValues(key, cursor, new ScanParams());
}

ScanResult<byte[]> hscanNoValues(byte[] key, byte[] cursor, ScanParams params);

long hstrlen(byte[] key, byte[] field);

}
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/commands/HashCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ default ScanResult<Map.Entry<String, String>> hscan(String key, String cursor) {

ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, ScanParams params);

default ScanResult<String> hscanNoValues(String key, String cursor) {
return hscanNoValues(key, cursor, new ScanParams());
}

ScanResult<String> hscanNoValues(String key, String cursor, ScanParams params);

long hstrlen(String key, String field);
}
Loading

0 comments on commit c02e5be

Please sign in to comment.