Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common interface for Jedis and JedisCluster

Tags:

redis

jedis

I see that Jedis and JedisCluster don't implement a common java interface, and I am wondering why. My software will be running in different environments where redis may or may not run in cluster mode, so how do I implement a common piece of code using Jedis that will run in both the environments?

The clients will be doing only basic operations and I want to hide the cluster operations within the library and not expose them. Any ideas on a modular design?

thanks.

like image 333
vrtx54234 Avatar asked Sep 19 '16 22:09

vrtx54234


People also ask

How connect Jedis to Redis?

The Java CodeJedis jedis = new Jedis("localhost"); // prints out "Connection Successful" if Java successfully connects to Redis server. Here is a breakdown of the above code: Jedis jedis = new Jedis("localhost"); This connects our Java to Redis server running on our local host.

Does Jedis support Redis cluster?

The latest version of Jedis has support to connect with Redis Cluster.

What is the difference between Redis and Jedis?

Two of the most popular Java client libraries for Redis are Redisson and Jedis. Redisson offers in-memory data grid features with support for a variety of distributed objects and services for Redis. Jedis, on the other hand, is a more lightweight offering that lacks certain features of other libraries.

Does Jedis support cluster?

Due to its simpler functionality, Jedis is easier to use, but it only works with clusters synchronously.


1 Answers

Looks like this may be your answer redis.clients.jedis.JedisCommands.

You can use this interface as argument to your methods and pass in either a Jedis or JedisCluster instance.

like image 61
leonardseymore Avatar answered Nov 15 '22 12:11

leonardseymore