Can Jedis get/set an Java POJO?

后端 未结 2 1298
陌清茗
陌清茗 2020-12-14 02:32

I\'m using Jedis as the java client to connect to Redis Servers.

Question 1: It seems there is no method to get/set Object < ? extends Serializa

2条回答
  •  独厮守ぢ
    2020-12-14 03:16

    Regard Question 1: Jedis won't handle POJOs. You should serialize to a string or byte[] and use jedis to do that, although I won't recommend to store your java objects serialized, as you won't be able to use all Redis cool features. A different approach would be to use something like a object-hash mapper, like JOhm.

    Regard Question 2: ShardedJedis will only support commands that run on a single key. This is to guarantee atomicity. If you want to run a specific command on a specific redis you should use shardedJedis.getShard('someky') which will return a Jedis instance that you can use. Another way to handle this, the recommended one, is to specify your password in the JedisShardInfo instances. You can see and example of this in the tests.

提交回复
热议问题