每个 servlet 一个 Lettuce Redis 连接?

One Lettuce Redis connection per servlet?

在 servlet 中,Lettuce Redis 连接应该在 init() 中创建并在 destroy() 中关闭,还是应该为每个请求创建一个连接(在 doPost 或 [=13= 中) ]?)

我正在使用同步 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.

这取决于你追求的场景。 如果您打算使用 Redis 事务,则必须确保不共享正在进行的事务连接。 如果没有,那么大多数情况下一个连接就足够了,因为 Redis 是单线程的,并且您的所有命令无论如何都会在命令队列中等待。

生菜在设计上是线程安全的,这对大多数情况来说已经足够了。所有 Redis 用户操作都是单线程执行的。使用多个连接不会以积极的方式影响应用程序的性能。

我有 5 个 redis reader。所以我的服务器应该并行连接执行 5 个命令。生菜确实是任何服务的瓶颈。