Redis Java Clients



As we know that, to connect with the relational database we need Driver, Similarly, we need a client to connect to a Redis database. A client allows us to communicate with the database programmatically. There are many Redis client that supports most of the programming languages. In this tutorial we will work with the most popular Java Client Jedis. Though there are Java clients as well such as Lettuce RJC, and Radisson, etc. To know more about Java Clients that Redis support click here

What is Jedis

Jedis is a java client library. It is a small lightweight and extremely fast client library in Java for Redis. Spring Data supports Jedis because the implementation of Redis using Jedis is painless. One thing to remember is that Jedis instance is not thread-safe, However using Jedis pool we can achieve thread-safety. Just make a note, Redis itself is a single−threaded which provides concurrency.

Jedis Pool

Jedis pool objects are thread−safe, and can be used for multiple threads. Instead of creating a new connection to the database each time when we send a database request we prefer using the pool. Pool keeps several connections open based on the pool configuration and when a request comes in, it takes a connection from the pool and returns it to the pool when the request is fulfilled. Doing so improves the performance by avoiding the creation of a new connection with each new request.

Advertisements