6

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.

vrtx54234
  • 2,196
  • 3
  • 30
  • 53
  • Dude, did you work this out? It's true that you can pass JedisCommands but that's very limited (it doesn't implement auth(password) common to both Jedis and JedisCluster), it's not auto closeable etc. – Richard Sep 10 '19 at 13:29

1 Answers1

2

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.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
leonardseymore
  • 533
  • 5
  • 20
  • 1
    JedisCluster implements JedisClusterCommands and not JedisCommands. Am I missing something? – vrtx54234 Nov 28 '16 at 21:22
  • 1
    public class JedisCluster extends BinaryJedisCluster implements JedisCommands, MultiKeyJedisClusterCommands, JedisClusterScriptingCommands – leonardseymore Nov 29 '16 at 12:23
  • Looks like both implement it in version 2.9.0. Unfortunately not all commands are available in the JedisCommands interface. I for example wanted to use Transactions and seem unavailable in JedisCluster. – leonardseymore Nov 29 '16 at 12:24
  • What about `BinaryJedis` and `BinaryJedisCluster` ? There are no common interfaces between the two as of Jedis version 2.9.x. How is the problem explained in this post solved with the binary version? – krackoder Sep 25 '18 at 18:03