JedisPooled vs JedisPool

296 views
Skip to first unread message

Oscar Besga

unread,
Aug 30, 2023, 6:02:00 PM8/30/23
to Jedis
Hi

I'm with my JedisExtraUtils project (https://github.com/oscar-besga-panel/JedisExtraUtils) and I use JedisPool in my classes.
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

Sazzadul Hoque

unread,
Aug 31, 2023, 2:12:47 AM8/31/23
to jedis...@googlegroups.com
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 ?

Not really. You won't save anything in terms of network round trip.
To optimize with sequential calls, you'll need pipelining.
 
Is there a way to convert a JedisPool into a JedisPooled and/or viceversa (using the same connections and connection pool under the hood)
 
No.

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jedis_redis/f9d7656b-6a8d-4015-ba38-dd8b5d87f883n%40googlegroups.com.

Oscar Besga

unread,
Nov 30, 2023, 4:50:37 PM11/30/23
to Jedis
Hi !

I've limited the helper to the JedisPool class
as it has no to litlle sense in JedisPooled

Take a look when you can      
Reply all
Reply to author
Forward
0 new messages