Question

I'm helping maintain an app that uses Jedis to connect to Sharded Redis.

The app I'm working with keeps an instance of the ShardedJedisPool in a service, to keep reusing it over multiple requests.

I was reviewing the docs on Sharded Jedis and noticed the following comment:

Forgetting pool.destroy keeps the connection open until timeout is reached.

Our app isn't calling pool.destroy() anywhere. Should we be calling pool.destroy() on every request? And I guess, creating a new pool on every request as well? Or can my pool stay alive for the lifetime of my service, and only call pool.destroy() in the finalize method of the service?

Était-ce utile?

La solution

Both ShardedJedisPool and JedisPool are intended to be created only once for the entire life of the application. And you destroy them when the application shutsdown. Both ShardedJedisPool and JedisPool are thread-safe, meanning that it is safe to use the same instance across threads (in your case requests) and get an instance of ShardedJedis or Jedis. After using ShardedJedis or Jedis, you should return them to the pool, or else the pool will get exhausted (depending on how you configured it).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top