Hi
I'm considering migrating it from JedisPool to JedisPooled (new kid on the code)
For what I see, JedisPooled uses internally the try-catch-resources; so for individual redis calls can be better to have less boilerplate code.
But if you use more than one redis call, it migth be better to use the classic try-with-resources and use the same connection object to the sequential calls.
Is my understanding correct ?
Is there a way to convert a JedisPool into a JedisPooled and/or viceversa (using the same connections and connection pool under the hood)
What do you this of this code
Code
default void withJedisPoolDo(Consumer<Jedis> consumer) {
try (Connection connection = getJedisPooled().getPool().getResource()) {
consumer.accept(new Jedis(connection));
}
}
Example
void example() {
withJedisPoolDo(jedis -> {
String s = jedis.get("my:key:001");
s = s + "example";
jedis.set("my:key:001", s);
jedis.expire("my:key:001", 3000);
});
}
Thanks