lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

Redis MULTI, connection pool and WS problem

Open activeperception opened this issue 6 years ago • 0 comments
trafficstars

Hi,

We came across an interesting situation when running our app which roughly has:

  • an event loop that keeps calling recv_frame. On close or error we call set_keepalive to keep the redis connection in a pool.
  • a function (called from within the event loop) that uses redis MULTI - EXEC to run multiple statements in a "transaction".

The issue is that sometimes the connection that get added to the pool is 'in the middle of a transaction' (we know this because, when the redis connection is reused a call to incrby for example returns QUEUED instead of the int).

It's a bit like as if the lua function that does MULTI - EXEC is preempted by the event loop before it can finish.

The redis function is very simple, just a MULTI...few INCR....an EXEC.

Maybe it's just me not understanding how lua-nginx concurrency model but I assumed that any lua function would be executed completely before any other function (i.e. the event loop cycle) could continue. Is that not the case?

The only other thing that I can think of is if the EXEC had to fail and leave the transaction still active. Is that a possibility? How to overcome that?

Thanks :)

activeperception avatar Nov 12 '19 07:11 activeperception