# Jedis guide (Java)

```json metadata
{
  "title": "Jedis guide (Java)",
  "description": "Connect your Java application to a Redis database",
  "categories": ["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],
  "tableOfContents": {"sections":[{"id":"install","title":"Install"},{"id":"connect-and-test","title":"Connect and test"},{"id":"more-information","title":"More information"}]}
}
```














[Jedis](https://github.com/redis/jedis) is a synchronous Java client for Redis.
Use [Lettuce](https://redis.io/docs/latest/develop/clients/lettuce) if you need
a more advanced Java client that also supports asynchronous and reactive connections.
The sections below explain how to install `Jedis` and connect your application
to a Redis database.

Jedis 7.2.0 introduced a new client connection API:

| New API class | Replaces | Use case |
| :-- | :-- | :-- |
| `RedisClient` | `UnifiedJedis`, `JedisPool`, `JedisPooled` | Single connection (with connection pooling) |
| `RedisClusterClient` | `JedisCluster` | Redis Cluster connections |
| `RedisSentinelClient` | `JedisSentinelPool` | Redis Sentinel connections |

The old client classes are now considered deprecated.


`Jedis` requires a running Redis server. See [here](https://redis.io/docs/latest/operate/oss_and_stack/install/) for Redis Open Source installation instructions.

## Install

To include `Jedis` as a dependency in your application, edit the dependency file, as follows.

* If you use **Maven**:   

  ```xml
  <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>7.2.0</version>
  </dependency>
  ```

* If you use **Gradle**: 

  ```
  repositories {
      mavenCentral()
  }
  //...
  dependencies {
      implementation 'redis.clients:jedis:7.2.0'
      //...
  }
  ```

* If you use the JAR files, download the latest Jedis and Apache Commons Pool2 JAR files from [Maven Central](https://central.sonatype.com/) or any other Maven repository.

* Build from [source](https://github.com/redis/jedis)


## Connect and test

Add the following imports to your source file:




Connect to localhost on port 6379:




After you have connected, you can check the connection by storing and
retrieving a simple [string](https://redis.io/docs/latest/develop/data-types/strings) value:




Store and retrieve a [hash](https://redis.io/docs/latest/develop/data-types/hashes):




Close the connection when you're done:




## More information

`Jedis` has a complete [API reference](https://www.javadoc.io/doc/redis.clients/jedis/latest/index.html) available on [javadoc.io/](https://javadoc.io/).
The `Jedis` [GitHub repository](https://github.com/redis/jedis) also has useful docs
and examples including a page about handling
[failover with Jedis](https://github.com/redis/jedis/blob/master/docs/failover.md)

See also the other pages in this section for more information and examples:
