|
32 | 32 | import redis.clients.jedis.util.KeyValue; |
33 | 33 | import redis.clients.jedis.util.Pool; |
34 | 34 |
|
| 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 | + * @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 | + */ |
35 | 91 | public class Jedis implements ServerCommands, DatabaseCommands, JedisCommands, JedisBinaryCommands, |
36 | 92 | ControlCommands, ControlBinaryCommands, ClusterCommands, ModuleCommands, GenericControlCommands, |
37 | 93 | SentinelCommands, CommandCommands, Closeable { |
|
0 commit comments