openresty/lua-resty-redis

[Feature Request] Pipeline coroutine safety

Opened this issue · 6 comments

When using a pipeline combined with a coroutine, some commands might get mixed into the pipeline. Please consider introducing pipeline objects, e.g.:

local pipe = red:start_pipeline()
pipe:set(...)
-- ...
for result in ipairs(pipe:commit()) do
  -- ...
end

In the current implementation, the underlay connection and the red object is 1:1. The pipeline in Redis will occupy the connection. So red:start_pipeline() is probably a syntax sugar which creates another redis connection with the current configuration of red.

In the current implementation, the underlay connection and the red object is 1:1. The pipeline in Redis will occupy the connection. So red:start_pipeline() is probably a syntax sugar which creates another redis connection with the current configuration of red.

or we can block the connection only when committing the pipeline, and let the user decide whether to create another connection?

What do you mean by "block the connection only when committing the pipeline"?

What do you mean by "block the connection only when committing the pipeline"?

Instead of creating a new connection, we lock the connection until the pipeline finishes

IMHO, it would make thing complex if we put the connection management inside the redis client.
If we ensure there is only one coroutine that can write to a cosocket, then we can implement pipeline safety in a lock-free way. This mechanism can be put outside a client so it can be used as a general solution, instead of being a complex and hard-to-maintain code inside a library.

IMHO, it would make thing complex if we put the connection management inside the redis client. If we ensure there is only one coroutine that can write to a cosocket, then we can implement pipeline safety in a lock-free way. This mechanism can be put outside a client so it can be used as a general solution, instead of being a complex and hard-to-maintain code inside a library.

I agree. I'm now using a strategy to clone if the connection is doing a pipeline.