Top Related Projects
Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
Redisson - Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava/Reactive API. Over 50 Redis or Valkey based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Spring, Tomcat, Scheduler, JCache API, Hibernate, RPC, local cache...
Redis Java client
Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
General purpose redis client
Quick Overview
Jedis is a popular Java client library for Redis, providing a simple and efficient way to interact with Redis databases. It offers a wide range of Redis commands and features, making it easy for Java developers to integrate Redis into their applications.
Pros
- Simple and intuitive API for Redis operations
- High performance and thread-safe implementation
- Supports Redis Cluster, Sentinel, and Pipelining
- Active development and community support
Cons
- Limited connection pooling options compared to some alternatives
- Lack of built-in support for some advanced Redis features
- May require additional configuration for complex use cases
- Some users report occasional stability issues in high-concurrency scenarios
Code Examples
- Basic Redis operations:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
String value = jedis.get("key");
System.out.println(value); // Output: value
jedis.close();
- Using Redis Lists:
Jedis jedis = new Jedis("localhost");
jedis.lpush("mylist", "item1", "item2", "item3");
List<String> items = jedis.lrange("mylist", 0, -1);
System.out.println(items); // Output: [item3, item2, item1]
jedis.close();
- Redis Transactions:
Jedis jedis = new Jedis("localhost");
Transaction t = jedis.multi();
t.set("key1", "value1");
t.set("key2", "value2");
t.exec();
jedis.close();
- Using Redis Pub/Sub:
Jedis jedis = new Jedis("localhost");
jedis.subscribe(new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
System.out.println("Received message: " + message);
}
}, "mychannel");
jedis.close();
Getting Started
To use Jedis in your Java project, first add the dependency to your build file:
For Maven:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.3.1</version>
</dependency>
For Gradle:
implementation 'redis.clients:jedis:4.3.1'
Then, you can start using Jedis in your Java code:
import redis.clients.jedis.Jedis;
public class JedisExample {
public static void main(String[] args) {
Jedis jedis = new Jedis("localhost");
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.println(value); // Output: bar
jedis.close();
}
}
Make sure you have a Redis server running on localhost (or specify the appropriate host and port when creating the Jedis instance).
Competitor Comparisons
Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
Pros of Lettuce
- Supports non-blocking, reactive programming model
- Better performance in high-concurrency scenarios
- More comprehensive Redis feature support, including Redis Cluster
Cons of Lettuce
- Steeper learning curve, especially for developers new to reactive programming
- More complex API compared to Jedis' simpler, synchronous approach
Code Comparison
Jedis:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
String value = jedis.get("key");
jedis.close();
Lettuce:
RedisClient client = RedisClient.create("redis://localhost");
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> commands = connection.sync();
commands.set("key", "value");
String value = commands.get("key");
connection.close();
client.shutdown();
Summary
Lettuce offers superior performance and more advanced features, making it suitable for complex, high-concurrency applications. However, it comes with a steeper learning curve. Jedis, on the other hand, provides a simpler, more straightforward API that's easier to use for basic Redis operations and smaller projects. The choice between the two depends on the specific requirements of your project and your team's familiarity with reactive programming concepts.
Redisson - Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava/Reactive API. Over 50 Redis or Valkey based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Spring, Tomcat, Scheduler, JCache API, Hibernate, RPC, local cache...
Pros of Redisson
- More comprehensive feature set, including distributed objects, locks, and services
- Built-in support for Redis clustering and high availability
- Better performance in multi-threaded environments
Cons of Redisson
- Steeper learning curve due to more complex API
- Larger library size, which may impact application startup time
- Less widespread adoption compared to Jedis
Code Comparison
Jedis:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
String value = jedis.get("key");
jedis.close();
Redisson:
Config config = new Config();
config.useSingleServer().setAddress("redis://localhost:6379");
RedissonClient redisson = Redisson.create(config);
RBucket<String> bucket = redisson.getBucket("key");
bucket.set("value");
String value = bucket.get();
redisson.shutdown();
Both Jedis and Redisson are popular Java clients for Redis, but they differ in their approach and feature set. Jedis offers a simpler, more straightforward API, making it easier for beginners to get started. However, Redisson provides a more robust set of features and better support for advanced Redis use cases, particularly in distributed environments. The choice between the two depends on the specific requirements of your project and your team's familiarity with Redis concepts.
Redis Java client
Pros of Jedis
- Well-established and widely used Redis client for Java
- Supports a broad range of Redis features and commands
- Simple and straightforward API for basic Redis operations
Cons of Jedis
- Lacks support for some advanced Redis features
- Not as performant as some newer Redis clients
- Limited connection pooling capabilities
Code Comparison
Jedis:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
String value = jedis.get("key");
jedis.close();
Jedis>:
// No code comparison available as Jedis> is not a valid repository
Additional Notes
It's important to note that the comparison requested is between Jedis and "Jedis>", but "Jedis>" is not a valid GitHub repository. The comparison provided focuses on the characteristics of Jedis itself, as there is no counterpart to compare it against.
Jedis is a popular Redis client for Java, offering a simple interface for interacting with Redis. It's suitable for many use cases but may lack some advanced features or performance optimizations found in newer clients. When choosing a Redis client, consider your specific requirements, such as performance needs, Redis feature support, and ease of use.
Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
Pros of Spring Data Redis
- Higher-level abstraction, providing a more Spring-like programming model
- Offers template classes for easier Redis operations and automatic serialization
- Integrates seamlessly with other Spring projects and supports dependency injection
Cons of Spring Data Redis
- Steeper learning curve for developers not familiar with Spring ecosystem
- May introduce unnecessary complexity for simple Redis operations
- Potentially slower performance due to additional abstraction layers
Code Comparison
Spring Data Redis:
@Autowired
private RedisTemplate<String, Object> redisTemplate;
public void setValue(String key, Object value) {
redisTemplate.opsForValue().set(key, value);
}
Jedis:
try (Jedis jedis = jedisPool.getResource()) {
jedis.set(key, value);
}
Key Differences
- Spring Data Redis provides a more abstracted and Spring-integrated approach
- Jedis offers a simpler, more direct interface to Redis operations
- Spring Data Redis handles connection management automatically, while Jedis requires manual connection handling
- Spring Data Redis supports various serialization strategies out of the box, whereas Jedis requires manual serialization
Both libraries are widely used and have active communities. The choice between them often depends on the project's requirements, existing technology stack, and developer preferences.
General purpose redis client
Pros of StackExchange.Redis
- Written in C#, offering better integration with .NET applications
- Supports more advanced Redis features like Pub/Sub, Lua scripting, and pipelining
- Generally faster performance in .NET environments
Cons of StackExchange.Redis
- Limited to .NET ecosystem, not suitable for Java or other platforms
- Steeper learning curve due to more complex API
- Less active community compared to Jedis
Code Comparison
StackExchange.Redis:
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
db.StringSet("key", "value");
string value = db.StringGet("key");
Jedis:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
String value = jedis.get("key");
jedis.close();
StackExchange.Redis offers a more robust connection management system with its ConnectionMultiplexer
, while Jedis provides a simpler, more straightforward API. StackExchange.Redis is ideal for .NET developers working on complex Redis implementations, whereas Jedis is better suited for Java developers or those seeking a more lightweight Redis client.
Both libraries are well-maintained and widely used in their respective ecosystems, but the choice between them largely depends on the programming language and specific requirements of your project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Jedis
What is Jedis?
Jedis is a Java client for Redis designed for performance and ease of use.
Are you looking for a high-level library to handle object mapping? See redis-om-spring!
How do I Redis?
Learn for free at Redis University
Build faster with the Redis Launchpad
Supported Redis versions
The most recent version of this library supports redis version 5.0, 6.0, 6.2, 7.0 and 7.2.
The table below highlights version compatibility of the most-recent library versions and Redis versions. Compatibility means communication features, and Redis command capabilities.
Jedis version | Supported Redis versions | JDK Compatibility |
---|---|---|
3.9+ | 5.0 and 6.2 Family of releases | 8, 11 |
>= 4.0 | Version 5.0 to current | 8, 11, 17 |
>= 5.0 | Version 6.0 to current | 8, 11, 17 |
Getting started
To get started with Jedis, first add it as a dependency in your Java project. If you're using Maven, that looks like this:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.0.0</version>
</dependency>
To use the cutting-edge Jedis, check here.
Next, you'll need to connect to Redis. Consider installing a redis-stack docker:
docker run -p 6379:6379 -it redis/redis-stack:latest
For many applications, it's best to use a connection pool. You can instantiate a Jedis connection pool like so:
JedisPool pool = new JedisPool("localhost", 6379);
With a JedisPool
instance, you can use a
try-with-resources
block to get a connection and run Redis commands.
Here's how to run a single SET command within a try-with-resources block:
try (Jedis jedis = pool.getResource()) {
jedis.set("clientName", "Jedis");
}
Jedis
instances implement most Redis commands. See the
Jedis Javadocs
for the complete list of supported commands.
Easier way of using connection pool
Using a try-with-resources block for each command may be cumbersome, so you may consider using JedisPooled.
JedisPooled jedis = new JedisPooled("localhost", 6379);
Now you can send commands like sending from Jedis.
jedis.sadd("planets", "Venus");
Connecting to a Redis cluster
Jedis lets you connect to Redis Clusters, supporting the Redis Cluster Specification.
To do this, you'll need to connect using JedisCluster
. See the example below:
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7380));
JedisCluster jedis = new JedisCluster(jedisClusterNodes);
Now you can use the JedisCluster
instance and send commands like you would with a standard pooled connection:
jedis.sadd("planets", "Mars");
Using Redis modules
Jedis includes support for Redis modules such as RedisJSON and RediSearch.
See the RedisJSON Jedis or RediSearch Jedis for details.
Failover
Jedis supports retry and failover for your Redis deployments. This is useful when:
- You have more than one Redis deployment. This might include two independent Redis servers or two or more Redis databases replicated across multiple active-active Redis Enterprise clusters.
- You want your application to connect to one deployment at a time and to fail over to the next available deployment if the first deployment becomes unavailable.
For the complete failover configuration options and examples, see the Jedis failover docs.
Documentation
The Jedis wiki contains several useful articles for using Jedis.
You can also check the latest Jedis Javadocs.
Some specific use-case examples can be found in redis.clients.jedis.examples
package of the test source codes.
Troubleshooting
If you run into trouble or have any questions, we're here to help!
Hit us up on the Redis Discord Server or Jedis GitHub Discussions or Jedis mailing list.
Contributing
We'd love your contributions!
Bug reports are always welcome! You can open a bug report on GitHub.
You can also contribute documentation -- or anything to improve Jedis. Please see contribution guideline for more details.
License
Jedis is licensed under the MIT license.
Sponsorship
Top Related Projects
Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
Redisson - Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava/Reactive API. Over 50 Redis or Valkey based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Spring, Tomcat, Scheduler, JCache API, Hibernate, RPC, local cache...
Redis Java client
Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
General purpose redis client
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot