Skip to content

Commit e8fdd20

Browse files
committed
Deprecate JedisPool and JedisSentinelPool
Provide clear guidance which client class should be used instead.
1 parent be9dc0e commit e8fdd20

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,62 @@
3232
import redis.clients.jedis.util.KeyValue;
3333
import redis.clients.jedis.util.Pool;
3434

35+
/**
36+
* Jedis is a lightweight Redis client that uses a single, non-pooled connection to Redis.
37+
* <p>
38+
* <b>Important:</b> For most production use cases, {@link RedisClient} is the recommended and
39+
* preferred option. {@code RedisClient} provides connection pooling, better resource management,
40+
* and improved performance for typical applications.
41+
* </p>
42+
* <p>
43+
* <b>When to use Jedis:</b>
44+
* </p>
45+
* <ul>
46+
* <li><b>Short-lived scripts or utilities:</b> When you need a simple, lightweight client for
47+
* one-off operations or command-line tools.</li>
48+
* <li><b>Testing and development:</b> For unit tests or local development where connection pooling
49+
* overhead is unnecessary.</li>
50+
* <li><b>Fine-grained connection control:</b> Advanced scenarios requiring explicit control over
51+
* individual connections, such as managing connection lifecycle manually or implementing custom
52+
* connection strategies.</li>
53+
* <li><b>Single-threaded applications:</b> Applications that execute Redis commands sequentially
54+
* from a single thread and don't benefit from connection pooling.</li>
55+
* </ul>
56+
* <p>
57+
* <b>When to use RedisClient instead:</b>
58+
* </p>
59+
* <ul>
60+
* <li><b>Production applications:</b> Any multi-threaded or high-throughput application should use
61+
* {@link RedisClient} for its connection pooling capabilities.</li>
62+
* <li><b>Web applications:</b> Server applications handling concurrent requests benefit from
63+
* connection pooling to avoid connection overhead.</li>
64+
* <li><b>Long-running services:</b> Applications that maintain persistent connections to Redis
65+
* should use {@link RedisClient} for better resource management.</li>
66+
* <li><b>Default choice:</b> If you're unsure which to use, choose {@link RedisClient}.</li>
67+
* </ul>
68+
* <p>
69+
* <b>Usage example:</b>
70+
* </p>
71+
*
72+
* <pre>
73+
* {
74+
* &#64;code
75+
* // Simple usage for a short-lived operation
76+
* try (Jedis jedis = new Jedis("localhost", 6379)) {
77+
* jedis.set("key", "value");
78+
* String value = jedis.get("key");
79+
* }
80+
* }
81+
* </pre>
82+
* <p>
83+
* <b>Note:</b> Each {@code Jedis} instance maintains a single connection. For concurrent access
84+
* from multiple threads, either use {@link RedisClient} with connection pooling, or create
85+
* separate {@code Jedis} instances per thread (not recommended for production).
86+
* </p>
87+
*
88+
* @see RedisClient for the recommended pooled client for production use
89+
* @see JedisPool for legacy pooled connections (deprecated, use RedisClient instead)
90+
*/
3591
public class Jedis implements ServerCommands, DatabaseCommands, JedisCommands, JedisBinaryCommands,
3692
ControlCommands, ControlBinaryCommands, ClusterCommands, ModuleCommands, GenericControlCommands,
3793
SentinelCommands, CommandCommands, Closeable {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
import redis.clients.jedis.util.JedisURIHelper;
1818

1919
/**
20-
* PoolableObjectFactory custom impl.
20+
* PooledObjectFactory implementation for creating and managing {@link Jedis} instances in connection pools.
21+
* <p>
22+
* This factory is used internally by {@link JedisPool} and {@link JedisSentinelPool} to create, validate,
23+
* and destroy pooled Jedis connections.
24+
* </p>
25+
*
26+
* @deprecated JedisFactory is used exclusively with the deprecated {@link JedisPool} and {@link JedisSentinelPool}
27+
* classes. For modern Redis clients ({@link RedisClient}, {@link RedisSentinelClient}), the framework
28+
* uses {@link ConnectionFactory} internally, which manages {@link Connection} objects instead of
29+
* {@link Jedis} instances. There is no direct replacement for JedisFactory as connection management
30+
* is handled automatically by the new client architecture.
2131
*/
22-
// Legacy
32+
@Deprecated
2333
public class JedisFactory implements PooledObjectFactory<Jedis> {
2434

2535
private static final Logger logger = LoggerFactory.getLogger(JedisFactory.class);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
import redis.clients.jedis.util.JedisURIHelper;
1414
import redis.clients.jedis.util.Pool;
1515

16-
// Legacy
16+
/**
17+
* JedisPool is a pooled connection client for standalone Redis servers.
18+
*
19+
* @deprecated Use {@link RedisClient} instead. RedisClient provides the same functionality
20+
* with a cleaner API and simplified constructor options. For basic usage, simple
21+
* constructors are available. For advanced configuration, use {@link RedisClient#builder()}.
22+
*/
23+
@Deprecated
1724
public class JedisPool extends Pool<Jedis> {
1825

1926
private static final Logger log = LoggerFactory.getLogger(JedisPool.class);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
import java.time.Duration;
44
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
55

6+
/**
7+
* Configuration class for {@link JedisPool} connection pooling.
8+
*
9+
* @deprecated JedisPoolConfig is used with the deprecated {@link JedisPool} and {@link JedisSentinelPool} classes.
10+
* Use {@link ConnectionPoolConfig} instead, which is designed for the modern {@link RedisClient}
11+
* and {@link RedisSentinelClient} classes. ConnectionPoolConfig provides the same pooling configuration
12+
* options with better integration into the new client architecture.
13+
*/
14+
@Deprecated
615
public class JedisPoolConfig extends GenericObjectPoolConfig<Jedis> {
716

817
public JedisPoolConfig() {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
import redis.clients.jedis.exceptions.JedisException;
1919
import redis.clients.jedis.util.Pool;
2020

21+
/**
22+
* JedisSentinelPool is a pooled connection client for Redis Sentinel deployments.
23+
*
24+
* @deprecated Use {@link RedisSentinelClient} instead. RedisSentinelClient provides the same functionality
25+
* with a cleaner API and simplified constructor options. For basic usage, simple
26+
* constructors are available. For advanced configuration, use {@link RedisSentinelClient#builder()}.
27+
*/
28+
@Deprecated
2129
public class JedisSentinelPool extends Pool<Jedis> {
2230

2331
private static final Logger LOG = LoggerFactory.getLogger(JedisSentinelPool.class);

0 commit comments

Comments
 (0)