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)?
With JedisPool you can do transactions, e.g., something like this:
try (Jedis jedis = pool.getResource()) {
Transaction t = jedis.multi();
t.sadd("planets", "Venus");
t.sadd("planets", "Mars");
t.exec();
}
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!
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