Search code examples
redislettuce

Redis Lettuce Connection and BLPOP


Lettuce is using a single shared native connection under the hood. Is it safe to use BLPOP blocking command with this design - will it block this shared native connection and affect other clients? I didn't find a concrete explanatory description for that in Lettuce docs.

Thanks in advance,


Solution

  • Using BLPOP/BLMOVE and similar commands block the connection for the duration of the response or until timeout. If you are using synchronous APIs, the calling thread would also be blocked on this IO. Meanwhile, other threads can continue issuing commands through other client connections without being impacted.

    In case the blocked connection is shared with other threads, commands from such other threads would be queued behind BLPOP/BLMOVE. As a side effect, all other threads sharing the blocked connection will experience delays until Redis responds back to the first BLPOP/BLMOVE command, after which the connection gets automatically unblocked and all queued commands would be executed FIFO. This is a classic head-of-the-line blocking pattern and will occur if you use blocking commands on a shared connection.

    In your specific use case, it is advisable not to use a shared connection for issuing blocking commands. The same rule applies to transactions and disabling flush for batched commands. This is one of the rare use cases where Lettuce connections should not be shared.