Git Product home page Git Product logo

jedis's Introduction

Jedis

Release Maven Central Javadocs MIT licensed Integration codecov Discord

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!

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:

  1. 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.
  2. 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

Redis Logo

jedis's People

Contributors

sazzad16 avatar heartsavior avatar marcosnils avatar xetorthio avatar gkorland avatar yaourt avatar dengliming avatar nykolaslima avatar ewhauser avatar chayim avatar mardambey avatar dependabot[bot] avatar phufool avatar zeekling avatar ivowiblo avatar avital-fine avatar yangbodong22011 avatar mindwind avatar samhendley avatar devfozgul avatar alextkachman avatar avitalfineredis avatar nrodrigues avatar taer avatar raszi avatar kevinsawicki avatar dvirdukhan avatar mayankdang avatar grdmitro avatar wangxu0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.