Skip to content

Commit afd7b68

Browse files
committed
Fix formatting and imports
1 parent 2734764 commit afd7b68

File tree

4 files changed

+129
-40
lines changed

4 files changed

+129
-40
lines changed

src/main/java/redis/clients/jedis/RedisClient.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,44 @@
1010
import redis.clients.jedis.util.JedisURIHelper;
1111
import redis.clients.jedis.util.Pool;
1212

13+
/**
14+
* {@code RedisClient} is the recommended client for connecting to standalone Redis deployments.
15+
* <p>
16+
* This class provides a modern, unified interface for interacting with Redis, supporting connection
17+
* pooling, authentication, and configuration via a fluent builder API.
18+
* </p>
19+
* <p>
20+
* {@code RedisClient} supersedes the deprecated {@link JedisPooled} and {@link UnifiedJedis}
21+
* classes, offering improved usability and extensibility. For new applications, use
22+
* {@code RedisClient} instead of the older classes.
23+
* </p>
24+
* <p>
25+
* Example usage:
26+
* </p>
27+
*
28+
* <pre>
29+
* {
30+
* &#64;code
31+
* RedisClient client = RedisClient.builder().host("localhost").port(6379).build();
32+
* }
33+
* </pre>
34+
* <p>
35+
* For advanced configuration, see the {@link RedisClient.Builder} class.
36+
* </p>
37+
*/
1338
public class RedisClient extends UnifiedJedis {
1439

1540
public RedisClient() {
1641
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
1742
}
1843

1944
/**
20-
* WARNING: This constructor only accepts a uri string as {@code url}. {@link JedisURIHelper#isValid(java.net.URI)}
21-
* can be used before this.
45+
* WARNING: This constructor only accepts a uri string as {@code url}.
46+
* {@link JedisURIHelper#isValid(java.net.URI)} can be used before this.
2247
* <p>
23-
* To use a host string, {@link #RedisClient(java.lang.String, int)} can be used with {@link Protocol#DEFAULT_PORT}.
24-
*
25-
* @param url
48+
* To use a host string, {@link #RedisClient(java.lang.String, int)} can be used with
49+
* {@link Protocol#DEFAULT_PORT}.
50+
* @param url redis url
2651
*/
2752
public RedisClient(final String url) {
2853
super(url);
@@ -37,14 +62,16 @@ public RedisClient(final HostAndPort hostAndPort) {
3762
}
3863

3964
public RedisClient(final String host, final int port, final String user, final String password) {
40-
super(new HostAndPort(host, port), DefaultJedisClientConfig.builder().user(user).password(password).build());
65+
super(new HostAndPort(host, port),
66+
DefaultJedisClientConfig.builder().user(user).password(password).build());
4167
}
4268

4369
public RedisClient(final URI uri) {
4470
super(uri);
4571
}
4672

47-
private RedisClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider, CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) {
73+
private RedisClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider,
74+
CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) {
4875
super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache);
4976
}
5077

@@ -54,12 +81,12 @@ private RedisClient(CommandExecutor commandExecutor, ConnectionProvider connecti
5481
* Obtain an instance via {@link #builder()}.
5582
* </p>
5683
*/
57-
static public class Builder extends StandaloneClientBuilder<RedisClient> {
84+
public static class Builder extends StandaloneClientBuilder<RedisClient> {
5885

5986
@Override
6087
protected RedisClient createClient() {
61-
return new RedisClient(commandExecutor, connectionProvider, commandObjects, clientConfig.getRedisProtocol(),
62-
cache);
88+
return new RedisClient(commandExecutor, connectionProvider, commandObjects,
89+
clientConfig.getRedisProtocol(), cache);
6390
}
6491
}
6592

@@ -80,4 +107,3 @@ public Pipeline pipelined() {
80107
return (Pipeline) super.pipelined();
81108
}
82109
}
83-

src/main/java/redis/clients/jedis/RedisClusterClient.java

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@
1313
import redis.clients.jedis.providers.ConnectionProvider;
1414
import redis.clients.jedis.util.JedisClusterCRC16;
1515

16+
/**
17+
* RedisClusterClient provides a high-level, unified interface for interacting with a Redis Cluster.
18+
* <p>
19+
* This class is intended as a modern replacement for the deprecated {@code JedisCluster} class. It
20+
* supports all cluster operations and is designed to work seamlessly with the {@link UnifiedJedis}
21+
* API, allowing for consistent usage patterns across standalone, sentinel, and cluster deployments.
22+
* <p>
23+
* <b>Usage:</b>
24+
*
25+
* <pre>
26+
* {
27+
* &#64;code
28+
* Set<HostAndPort> clusterNodes = new HashSet<>();
29+
* clusterNodes.add(new HostAndPort("127.0.0.1", 7000));
30+
* RedisClusterClient client = new RedisClusterClient(clusterNodes);
31+
* client.set("key", "value");
32+
* String value = client.get("key");
33+
* }
34+
* </pre>
35+
* <p>
36+
* <b>Migration:</b> Users of {@code JedisCluster} are encouraged to migrate to this class for
37+
* improved API consistency, better resource management, and enhanced support for future Redis
38+
* features.
39+
* <p>
40+
* <b>Thread-safety:</b> This client is thread-safe and can be shared across multiple threads.
41+
* <p>
42+
* <b>Configuration:</b> Various constructors allow for flexible configuration, including
43+
* authentication and custom timeouts.
44+
*/
1645
public class RedisClusterClient extends UnifiedJedis {
1746

1847
public static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError";
@@ -28,35 +57,46 @@ public class RedisClusterClient extends UnifiedJedis {
2857
public static final int DEFAULT_MAX_ATTEMPTS = 5;
2958

3059
/**
31-
* Creates a RedisClusterClient instance. The provided node is used to make the first contact with the cluster.
60+
* Creates a RedisClusterClient instance. The provided node is used to make the first contact with
61+
* the cluster.
3262
* <p>
33-
* Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms is being used with
34-
* {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum attempts.
63+
* Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms
64+
* is being used with {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum
65+
* attempts.
3566
* @param node Node to first connect to.
3667
*/
3768
public RedisClusterClient(HostAndPort node) {
38-
super(new ClusterConnectionProvider(Collections.singleton(node), DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()),
69+
super(
70+
new ClusterConnectionProvider(Collections.singleton(node),
71+
DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()),
3972
DEFAULT_MAX_ATTEMPTS, Duration.ofMillis((long) DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS));
4073
}
4174

4275
/**
4376
* Creates a RedisClusterClient with multiple entry points.
4477
* <p>
45-
* Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms is being used with
46-
* {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum attempts.
78+
* Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms
79+
* is being used with {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum
80+
* attempts.
4781
* @param nodes Nodes to connect to.
4882
*/
4983
public RedisClusterClient(Set<HostAndPort> nodes) {
50-
super(new ClusterConnectionProvider(nodes, DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()),
84+
super(
85+
new ClusterConnectionProvider(nodes,
86+
DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()),
5187
DEFAULT_MAX_ATTEMPTS, Duration.ofMillis((long) DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS));
5288
}
5389

5490
public RedisClusterClient(Set<HostAndPort> nodes, String user, String password) {
55-
super(new ClusterConnectionProvider(nodes, DefaultJedisClientConfig.builder().user(user).password(password).build()),
56-
DEFAULT_MAX_ATTEMPTS, Duration.ofMillis((long) Protocol.DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS));
91+
super(
92+
new ClusterConnectionProvider(nodes,
93+
DefaultJedisClientConfig.builder().user(user).password(password).build()),
94+
DEFAULT_MAX_ATTEMPTS,
95+
Duration.ofMillis((long) Protocol.DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS));
5796
}
5897

59-
private RedisClusterClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider, CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) {
98+
private RedisClusterClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider,
99+
CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) {
60100
super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache);
61101
}
62102

@@ -70,8 +110,8 @@ static public class Builder extends ClusterClientBuilder<RedisClusterClient> {
70110

71111
@Override
72112
protected RedisClusterClient createClient() {
73-
return new RedisClusterClient(commandExecutor, connectionProvider, commandObjects, clientConfig.getRedisProtocol(),
74-
cache);
113+
return new RedisClusterClient(commandExecutor, connectionProvider, commandObjects,
114+
clientConfig.getRedisProtocol(), cache);
75115
}
76116
}
77117

@@ -95,7 +135,8 @@ public Map<String, ConnectionPool> getClusterNodes() {
95135
/**
96136
* Returns the connection for one of the 16,384 slots.
97137
* @param slot the slot to retrieve the connection for.
98-
* @return connection of the provided slot. {@code close()} of this connection must be called after use.
138+
* @return connection of the provided slot. {@code close()} of this connection must be called
139+
* after use.
99140
*/
100141
public Connection getConnectionFromSlot(int slot) {
101142
return ((ClusterConnectionProvider) provider).getConnectionFromSlot(slot);
@@ -125,7 +166,8 @@ public void ssubscribe(BinaryJedisShardedPubSub jedisPubSub, final byte[]... cha
125166

126167
@Override
127168
public ClusterPipeline pipelined() {
128-
return new ClusterPipeline((ClusterConnectionProvider) provider, (ClusterCommandObjects) commandObjects);
169+
return new ClusterPipeline((ClusterConnectionProvider) provider,
170+
(ClusterCommandObjects) commandObjects);
129171
}
130172

131173
/**
@@ -140,9 +182,9 @@ public AbstractTransaction transaction(boolean doMulti) {
140182

141183
public final <T> T executeCommandToReplica(CommandObject<T> commandObject) {
142184
if (!(executor instanceof ClusterCommandExecutor)) {
143-
throw new UnsupportedOperationException("Support only execute to replica in ClusterCommandExecutor");
185+
throw new UnsupportedOperationException(
186+
"Support only execute to replica in ClusterCommandExecutor");
144187
}
145188
return ((ClusterCommandExecutor) executor).executeCommandToReplica(commandObject);
146189
}
147190
}
148-

src/main/java/redis/clients/jedis/RedisSentinelClient.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
package redis.clients.jedis;
22

3-
import java.util.Set;
4-
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
5-
import redis.clients.jedis.annots.Experimental;
63
import redis.clients.jedis.builders.SentinelClientBuilder;
74
import redis.clients.jedis.csc.Cache;
8-
import redis.clients.jedis.csc.CacheConfig;
9-
import redis.clients.jedis.csc.CacheFactory;
5+
106
import redis.clients.jedis.executors.CommandExecutor;
117
import redis.clients.jedis.providers.ConnectionProvider;
128
import redis.clients.jedis.providers.SentineledConnectionProvider;
139

10+
/**
11+
* A high-level client for interacting with Redis Sentinel-managed Redis deployments.
12+
* <p>
13+
* {@code RedisSentinelClient} provides robust support for automatic master failover, connection
14+
* management, and command execution in environments where Redis Sentinel is used to monitor and
15+
* manage Redis servers.
16+
* </p>
17+
* <p>
18+
* Usage:
19+
* </p>
20+
*
21+
* <pre>
22+
* RedisSentinelClient client = RedisSentinelClient.builder().sentinel("localhost", 26379)
23+
* .masterName("mymaster").build();
24+
* </pre>
25+
* <p>
26+
* <b>Relationship to {@code JedisSentineled}:</b>
27+
* <ul>
28+
* <li>{@code RedisSentinelClient} is the recommended replacement for the deprecated
29+
* {@code JedisSentineled} class.</li>
30+
* <li>It offers improved API consistency, better failover handling, and a fluent builder for
31+
* configuration.</li>
32+
* <li>Use {@code RedisSentinelClient} for new codebases and when migrating from
33+
* {@code JedisSentineled}.</li>
34+
* </ul>
35+
* </p>
36+
*/
1437
public class RedisSentinelClient extends UnifiedJedis {
15-
16-
private RedisSentinelClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider, CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) {
38+
private RedisSentinelClient(CommandExecutor commandExecutor,
39+
ConnectionProvider connectionProvider, CommandObjects commandObjects,
40+
RedisProtocol redisProtocol, Cache cache) {
1741
super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache);
1842
}
1943

@@ -23,18 +47,17 @@ private RedisSentinelClient(CommandExecutor commandExecutor, ConnectionProvider
2347
* Obtain an instance via {@link #builder()}.
2448
* </p>
2549
*/
26-
static public class Builder extends SentinelClientBuilder<RedisSentinelClient> {
50+
public static class Builder extends SentinelClientBuilder<RedisSentinelClient> {
2751

2852
@Override
2953
protected RedisSentinelClient createClient() {
30-
return new RedisSentinelClient(commandExecutor, connectionProvider, commandObjects, clientConfig.getRedisProtocol(),
31-
cache);
54+
return new RedisSentinelClient(commandExecutor, connectionProvider, commandObjects,
55+
clientConfig.getRedisProtocol(), cache);
3256
}
3357
}
3458

3559
/**
3660
* Create a new builder for configuring RedisSentinelClient instances.
37-
*
3861
* @return a new {@link RedisSentinelClient.Builder} instance
3962
*/
4063
public static Builder builder() {
@@ -50,4 +73,3 @@ public Pipeline pipelined() {
5073
return (Pipeline) super.pipelined();
5174
}
5275
}
53-

src/main/java/redis/clients/jedis/UnifiedJedis.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import redis.clients.jedis.json.JsonSetParams;
2727
import redis.clients.jedis.json.Path;
2828
import redis.clients.jedis.json.Path2;
29-
import redis.clients.jedis.mcf.MultiDbCommandExecutor;
3029
import redis.clients.jedis.params.VAddParams;
3130
import redis.clients.jedis.params.VSimParams;
3231
import redis.clients.jedis.resps.RawVector;

0 commit comments

Comments
 (0)