skip to Main Content

In a servlet, should Lettuce Redis connections be created in init() and shutdown in destroy() or should a connection be created for every request (in doPost or doGet?)

I am using sync RedisCommands (connection.sync())

Lettuce states:

Lettuce is thread-safe by design which is sufficient for most cases. All Redis user operations are executed single-threaded. Using multiple connections does not impact the performance of an application in a positive way. The use of blocking operations usually goes hand in hand with worker threads that get their dedicated connection. The use of Redis Transactions is the typical use case for dynamic connection pooling as the number of threads requiring a dedicated connection tends to be dynamic. That said, the requirement for dynamic connection pooling is limited. Connection pooling always comes with a cost of complexity and maintenance.

2

Answers


  1. it depends on a scenario you are chasing.
    If you intend to use redis transactions, then you have to make sure ongoing transaction connection is not shared.
    If not, then one connection will be sufficient for most cases, since redis is single threaded and all your commands will be waiting in a command queue anyway.

    Login or Signup to reply.
  2. Lettuce is thread-safe by design which is sufficient for most cases. All Redis user operations are executed single-threaded. Using multiple connections does not impact the performance of an application in a positive way.

    I have 5 redis reader. So my server should make execute 5 commands in parallel connection. Lettuce is really bottleneck for any service.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search