Introduction
Jedis is a synchronous, blocking Java client for Redis maintained under the official redis organization on GitHub. It provides a direct mapping of Redis commands to Java methods, making it simple to adopt. Jedis is one of the two recommended Java clients alongside Lettuce.
What Jedis Does
- Executes all Redis commands via a clean, method-per-command Java API
- Supports connection pooling through JedisPool and the newer JedisPooled wrapper
- Provides pipelining to batch multiple commands into a single network round trip
- Handles Redis transactions (MULTI/EXEC) and Lua script evaluation (EVAL)
- Connects to Redis Cluster and Redis Sentinel for high-availability setups
Architecture Overview
Jedis uses a simple blocking I/O model: each Jedis instance wraps a single TCP socket to a Redis server. For concurrent applications, JedisPool manages a pool of these instances backed by Apache Commons Pool 2. The newer JedisPooled class simplifies usage by auto-borrowing and returning connections per call. For Redis Cluster, JedisCluster discovers the slot-to-node mapping and routes commands accordingly.
Self-Hosting & Configuration
- Add the Jedis Maven or Gradle dependency to your Java project
- Create a JedisPooled instance pointing to your Redis host and port
- Configure pool size via GenericObjectPoolConfig (maxTotal, maxIdle, minIdle)
- For Redis Cluster, use JedisCluster with a set of seed HostAndPort entries
- For Sentinel, use JedisSentinelPool with the master name and sentinel addresses
Key Features
- Full coverage of Redis commands including Streams, JSON, and Search modules
- Built-in connection pooling with configurable eviction and validation policies
- Pipeline mode for batching commands and reducing network round trips
- Support for Redis Cluster automatic slot discovery and failover
- Lightweight dependency chain: only Apache Commons Pool 2 and SLF4J
Comparison with Similar Tools
- Lettuce — async and reactive; Jedis is simpler but synchronous only
- Redisson — higher-level distributed objects and locks; Jedis is lower-level
- Spring Data Redis — abstracts over Jedis or Lettuce with Spring integration
- ioredis (Node.js) — similar philosophy but for the JavaScript ecosystem
- redis-py (Python) — the Python equivalent of Jedis
FAQ
Q: Jedis vs Lettuce — which should I pick? A: Use Jedis for simple, blocking workloads. Use Lettuce if you need non-blocking I/O, reactive streams, or shared connections across threads.
Q: Is Jedis thread-safe? A: A single Jedis instance is not thread-safe. Use JedisPool or JedisPooled for concurrent access.
Q: Does Jedis support Redis modules like RedisJSON? A: Yes. Jedis 4.x+ includes APIs for RedisJSON, RediSearch, RedisBloom, and RedisTimeSeries.
Q: Can I use Jedis with Spring Boot? A: Yes. Spring Data Redis supports Jedis as an alternative to its default Lettuce driver.