Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JedisPool vs JedisPooled

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)?

like image 304
parpar8090 Avatar asked Jul 20 '26 20:07

parpar8090


1 Answers

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!

like image 146
Mαx Φ Avatar answered Jul 22 '26 10:07

Mαx Φ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!