fred.rs icon indicating copy to clipboard operation
fred.rs copied to clipboard

[Feature] TransactionInterface for Pipeline

Open ItsEthra opened this issue 1 year ago • 1 comments

I noticed that Pipeline<T> does not implement TransactionsInterface which means I cannot use MULTI on it. Is there any specific reason why it's not implemented? AFAIK Commands in a pipeline are not executed together as a transaction. And also commands in a transaction are not executed in a pipeline(see below).

image

But I want to have commands executed together in a transaction AND in a pipeline together so I can cut on round trips and have them executed in order.

Describe the solution you'd like I would like to see TransactionsInterface implemented for Pipeline<T>.

ItsEthra avatar Jul 30 '24 20:07 ItsEthra

Yeah, I disallowed that in order to properly handle cluster redirections in the middle of transactions. The docs state that clients should DISCARD a transaction in response to a MOVED/ASK error, then replay the entire transaction on the new node, and the only way I could think to do that safely in a transaction was to wait for a QUEUED or MOVED/ASK response from each command.

I'm not sure if this changed in a recent Redis update, or whether the docs just never mentioned this, but in some testing earlier today I noticed that the server will respond with an EXECABORT error in this case, so it may be possible to safely do this. I'll have to look a bit further at older versions to make sure this is backwards compatible enough to depend on.

aembke avatar Aug 07 '24 22:08 aembke

After looking into this a bit more it seems Redis has supported this since 2.6.5. In 9.2.0 there will be a new pipeline function on the Transaction struct that can do this.

aembke avatar Sep 04 '24 22:09 aembke

Added in https://github.com/aembke/fred.rs/releases/tag/v9.2.0, but let me know if you have any issues with it.

aembke avatar Sep 04 '24 23:09 aembke

@aembke Why the pipeline function has been removed from Transaction since 10.x?

xhanl avatar Jan 18 '25 13:01 xhanl

All transactions are pipelined automatically now in 10.x.

aembke avatar Jan 18 '25 15:01 aembke