Looking at the Jedis Getting Started, I understand it’s better to use connection pools to be threadsafe. To do so, I would need a JedisPool
and a try-with-resources
statement like so:
try (Jedis jedis = pool.getResource()) {
jedis.set("hello", "world");
}
But then there’s JedisPooled
, which is the same as JedisPool
just without the try-with-resources
.
JedisPooled jedis = new JedisPooled("localhost", 6379);
jedis.sadd("hellow", "world");
So the question is, is there any other difference between JedisPool/Pooled, and why should I prefer JedisPool over JedisPooled (or vice versa)?
2
Answers
With
JedisPool
you can do transactions, e.g., something like this:It doesn’t seem like you can do anything similar with
JedisPooled
.Probably, there’s more to that, but that’s what I’ve stumbled on by myself.
Hope that helps!
My understanding is that each command in JedisPooled
will get the resource from the pool and release the resource into the pool without having to do try-with-resources.
JedisPool needs explicit try-with-resources
REF : https://redis.io/docs/clients/java/