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.
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.
The latest version of Jedis has support to connect with Redis Cluster.
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.
Due to its simpler functionality, Jedis is easier to use, but it only works with clusters synchronously.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With