On Sep 30, 7:49 pm, Jonathan Leibiusky <
ionat...@gmail.com> wrote:
> Hi!
> Yes came to the right conclusion. Jedis is not thread safe (should add that
> to the documentation).
> You can either use one Jedis per thread or JedisPool, which is a thread safe
> pool of jedis.
>
> I would recommend JedisPool for most cases since it will reuse Jedis
> instances, resulting in better performance.
>
> It is easy to use, just create it and store it somewhere accesible for all
> threads. For example:
>
> class JedisFactory {
> public JedisPool jedisPool;
> static void JedisFactory() {
> jedisPool = new JedisPool("localhost");
> jedisPool.init();
> }
>
> }
>
> and from your thread:
>
> Jedis jedis = JedisFactory.jedisPool.getResource();
> ...
> ...
> JedisFactory.jedisPool.returnResource(jedis);
>
> Returning the resource to the Pool is important, so remember to do it.
> Otherwise when closing your app it'll wait for the resource to return.
>
> Oh, and one last thing... call jedisPool.destroy() when finishing your app.
>
> Jonathan
>