Skip to content

Commit

Permalink
Merge branch 'redis:master' into bugfix-resolve-all-hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
adiamzn authored and EC2 Default User committed Dec 13, 2021
2 parents c9f42b1 + 022a9af commit b3c752e
Show file tree
Hide file tree
Showing 20 changed files with 932 additions and 778 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<properties>
<github.global.server>github</github.global.server>
<log4j.version>2.13.3</log4j.version>
<log4j.version>2.15.0</log4j.version>
<jedis.module.name>redis.clients.jedis</jedis.module.name>
</properties>

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/redis/clients/jedis/ClusterPipeline.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
package redis.clients.jedis;

import java.util.Set;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.providers.ClusterConnectionProvider;
import redis.clients.jedis.util.IOUtils;

public class ClusterPipeline extends MultiNodePipelineBase {

private final ClusterConnectionProvider provider;
private AutoCloseable closeable = null;

public ClusterPipeline(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig) {
this(new ClusterConnectionProvider(clusterNodes, clientConfig));
this.closeable = this.provider;
}

public ClusterPipeline(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig,
GenericObjectPoolConfig<Connection> poolConfig) {
this(new ClusterConnectionProvider(clusterNodes, clientConfig, poolConfig));
this.closeable = this.provider;
}

public ClusterPipeline(ClusterConnectionProvider provider) {
super(new ClusterCommandObjects());
this.provider = provider;
}

@Override
public void close() {
try {
super.close();
} finally {
IOUtils.closeQuietly(closeable);
}
}

@Override
protected HostAndPort getNodeKey(CommandArguments args) {
return provider.getNode(((ClusterCommandArguments) args).getCommandHashSlot());
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ public List<byte[]> getBinaryMultiBulkReply() {
return (List<byte[]>) readProtocolWithCheckingBroken();
}

@Deprecated
public List<Object> getRawObjectMultiBulkReply() {
return getUnflushedObjectMultiBulkReply();
}

@SuppressWarnings("unchecked")
public List<Object> getUnflushedObjectMultiBulkReply() {
return (List<Object>) readProtocolWithCheckingBroken();
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ public DefaultJedisSocketFactory(HostAndPort hostAndPort, JedisClientConfig conf
}
}

private void connectToFirstSuccsefulHost(Socket socket, HostAndPort hostAndPort) throws IOException {
private void connectToFirstSuccsefulHost(Socket socket, HostAndPort hostAndPort) throws Exception {
List<InetAddress> hosts = Arrays.asList(InetAddress.getAllByName(hostAndPort.getHost()));
Collections.shuffle(hosts);
List<Exception> exceptions = new ArrayList<Exception>();
boolean connected = false;
JedisConnectionException jce = new JedisConnectionException("Failed to connect to any host resolved for DNS name.");
for (InetAddress host : hosts) {
try {
socket.connect(new InetSocketAddress(host.getHostAddress(), hostAndPort.getPort()), connectionTimeout);
connected = true;
break;
return;
} catch (Exception e) {
exceptions.add(e);
jce.addSuppressed(e);
}
}
if (!connected) {
throw new ConnectException(exceptions.toString());
}
throw jce;
}

@Override
Expand Down Expand Up @@ -124,11 +120,13 @@ public Socket createSocket() throws JedisConnectionException {

return socket;

} catch (IOException ex) {

} catch (Exception ex) {
IOUtils.closeQuietly(socket);

throw new JedisConnectionException("Failed to create socket.", ex);
if (ex instanceof JedisConnectionException) {
throw (JedisConnectionException) ex;
} else {
throw new JedisConnectionException("Failed to create socket.", ex);
}
}
}

Expand Down
427 changes: 213 additions & 214 deletions src/main/java/redis/clients/jedis/Jedis.java

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,80 +108,80 @@ public JedisCluster(Set<HostAndPort> nodes, int timeout,
this(nodes, timeout, DEFAULT_MAX_ATTEMPTS, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int timeout, int maxAttempts,
public JedisCluster(Set<HostAndPort> clusterNodes, int timeout, int maxAttempts,
final GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, timeout, timeout, maxAttempts, poolConfig);
this(clusterNodes, timeout, timeout, maxAttempts, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts, final GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, null, poolConfig);
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout, int soTimeout,
int maxAttempts, final GenericObjectPoolConfig<Connection> poolConfig) {
this(clusterNodes, connectionTimeout, soTimeout, maxAttempts, null, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts, String password, GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, password, null, poolConfig);
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout, int soTimeout,
int maxAttempts, String password, GenericObjectPoolConfig<Connection> poolConfig) {
this(clusterNodes, connectionTimeout, soTimeout, maxAttempts, password, null, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout,
int soTimeout, int maxAttempts, String password, String clientName,
GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, null, password, clientName,
this(clusterNodes, connectionTimeout, soTimeout, maxAttempts, null, password, clientName,
poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts, String user, String password, String clientName,
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout, int soTimeout,
int maxAttempts, String user, String password, String clientName,
GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
this(clusterNodes, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).user(user).password(password).clientName(clientName).build(),
maxAttempts, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout,
int soTimeout, int infiniteSoTimeout, int maxAttempts, String user, String password,
String clientName, GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
this(clusterNodes, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).blockingSocketTimeoutMillis(infiniteSoTimeout)
.user(user).password(password).clientName(clientName).build(), maxAttempts, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts, String password, String clientName,
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout, int soTimeout,
int maxAttempts, String password, String clientName,
GenericObjectPoolConfig<Connection> poolConfig, boolean ssl) {
this(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, null, password, clientName,
this(clusterNodes, connectionTimeout, soTimeout, maxAttempts, null, password, clientName,
poolConfig, ssl);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts, String user, String password, String clientName,
public JedisCluster(Set<HostAndPort> clusterNodes, int connectionTimeout, int soTimeout,
int maxAttempts, String user, String password, String clientName,
GenericObjectPoolConfig<Connection> poolConfig, boolean ssl) {
this(jedisClusterNode, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
this(clusterNodes, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).user(user).password(password).clientName(clientName).ssl(ssl).build(),
maxAttempts, poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, JedisClientConfig clientConfig,
public JedisCluster(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig,
int maxAttempts, GenericObjectPoolConfig<Connection> poolConfig) {
this(jedisClusterNode, clientConfig, maxAttempts,
this(clusterNodes, clientConfig, maxAttempts,
Duration.ofMillis((long) clientConfig.getSocketTimeoutMillis() * maxAttempts), poolConfig);
}

public JedisCluster(Set<HostAndPort> jedisClusterNode, JedisClientConfig clientConfig,
public JedisCluster(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig,
int maxAttempts, Duration maxTotalRetriesDuration, GenericObjectPoolConfig<Connection> poolConfig) {
super(jedisClusterNode, clientConfig, poolConfig, maxAttempts, maxTotalRetriesDuration);
super(clusterNodes, clientConfig, poolConfig, maxAttempts, maxTotalRetriesDuration);
}

public JedisCluster(Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig) {
this(jedisClusterNodes, clientConfig, DEFAULT_MAX_ATTEMPTS);
public JedisCluster(Set<HostAndPort> clusterNodess, JedisClientConfig clientConfig) {
this(clusterNodess, clientConfig, DEFAULT_MAX_ATTEMPTS);
}

public JedisCluster(Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts) {
super(jedisClusterNodes, clientConfig, maxAttempts);
public JedisCluster(Set<HostAndPort> clusterNodess, JedisClientConfig clientConfig, int maxAttempts) {
super(clusterNodess, clientConfig, maxAttempts);
}

public JedisCluster(Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts, Duration maxTotalRetriesDuration) {
super(jedisClusterNodes, clientConfig, maxAttempts, maxTotalRetriesDuration);
public JedisCluster(Set<HostAndPort> clusterNodess, JedisClientConfig clientConfig, int maxAttempts, Duration maxTotalRetriesDuration) {
super(clusterNodess, clientConfig, maxAttempts, maxTotalRetriesDuration);
}

public Map<String, ConnectionPool> getClusterNodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected final <T> Response<T> appendCommand(CommandObject<T> commandObject) {
}

@Override
public final void close() {
public void close() {
sync();
for (Connection connection : connections.values()) {
connection.close();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/redis/clients/jedis/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public List<Object> syncAndReturnAll() {
}
}

@Deprecated
public final boolean hasPipelinedResponse() {
return getPipelinedResponseLength() > 0;
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/redis/clients/jedis/Sentinel.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public String sentinelMyId() {
* 24) "2"
*
* </pre>
* @return
*/
@Override
public List<Map<String, String>> sentinelMasters() {
Expand Down Expand Up @@ -299,7 +298,6 @@ public List<String> sentinelGetMasterAddrByName(String masterName) {
* (integer) 1
* </pre>
* @param pattern
* @return
*/
@Override
public Long sentinelReset(String pattern) {
Expand Down Expand Up @@ -340,7 +338,6 @@ public Long sentinelReset(String pattern) {
* 28) "100"
* </pre>
* @param masterName
* @return
*/
@Override
public List<Map<String, String>> sentinelSlaves(String masterName) {
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/redis/clients/jedis/ShardedPipeline.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
package redis.clients.jedis;

import redis.clients.jedis.providers.ShardedConnectionProvider;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.providers.ShardedConnectionProvider;
import redis.clients.jedis.util.Hashing;
import redis.clients.jedis.util.IOUtils;

public class ShardedPipeline extends MultiNodePipelineBase {

private final ShardedConnectionProvider provider;
private AutoCloseable closeable = null;

public ShardedPipeline(List<HostAndPort> shards, JedisClientConfig clientConfig) {
this(new ShardedConnectionProvider(shards, clientConfig));
this.closeable = this.provider;
}

public ShardedPipeline(ShardedConnectionProvider provider) {
super(new ShardedCommandObjects(provider.getHashingAlgo()));
this.provider = provider;
}

public ShardedPipeline(List<HostAndPort> shards, JedisClientConfig clientConfig,
GenericObjectPoolConfig<Connection> poolConfig, Hashing algo, Pattern tagPattern) {
this(new ShardedConnectionProvider(shards, clientConfig, poolConfig, algo), tagPattern);
this.closeable = this.provider;
}

public ShardedPipeline(ShardedConnectionProvider provider, Pattern tagPattern) {
super(new ShardedCommandObjects(provider.getHashingAlgo(), tagPattern));
this.provider = provider;
}

@Override
public void close() {
try {
super.close();
} finally {
IOUtils.closeQuietly(closeable);
}
}

@Override
protected HostAndPort getNodeKey(CommandArguments args) {
return provider.getNode(((ShardedCommandArguments) args).getKeyHash());
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/redis/clients/jedis/params/ScanParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public ScanParams match(final byte[] pattern) {

/**
* @see <a href="https://redis.io/commands/scan#the-match-option">MATCH option in Redis documentation</a>
*
* @param pattern
* @return
*/
public ScanParams match(final String pattern) {
params.put(MATCH, ByteBuffer.wrap(SafeEncoder.encode(pattern)));
Expand All @@ -38,9 +35,6 @@ public ScanParams match(final String pattern) {

/**
* @see <a href="https://redis.io/commands/scan#the-count-option">COUNT option in Redis documentation</a>
*
* @param count
* @return
*/
public ScanParams count(final Integer count) {
params.put(COUNT, ByteBuffer.wrap(Protocol.toByteArray(count)));
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/redis/clients/jedis/params/SetParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ public static SetParams setParams() {
return new SetParams();
}

/**
* Set the specified expire time, in seconds.
* @param secondsToExpire
* @return SetParams
* @deprecated Use {@link #ex(long)}.
*/
@Deprecated
public SetParams ex(int secondsToExpire) {
return ex((long) secondsToExpire);
}

/**
* Set the specified expire time, in seconds.
* @param secondsToExpire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import redis.clients.jedis.util.SafeEncoder;

/**
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
* Builder Class for {@code SORT} command parameters.
*/
public class SortingParams implements IParams {
private final List<byte[]> params = new ArrayList<>();
Expand Down

0 comments on commit b3c752e

Please sign in to comment.