go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

Client.Pipelined().TxPipeline() is not a transaction?

Open ash2k opened this issue 3 years ago • 3 comments

Hi! Just getting familiar with the library and I'm looking to do the following:

var c *redis.Client = ...
_, err := c.Pipelined(ctx, func(p redis.Pipeliner) error {
    // Do stuff with p
    // ....

    // Inner transactions
    for ... {
        _, er r:= p.TxPipelined(ctx, func(pTx redis.Pipeliner) error {
            // Do stuff with pTx
        }
    }
    // Do more stuff with p
    // ....

    return err
}

https://github.com/go-redis/redis/blob/143859e34596a8e80ee858b5842d503d86572249/pipeline.go#L118-L137

The code above does not seem to wrap the nested pipeline into a transaction, is that right? Is that a bug?

ash2k avatar Dec 17 '20 09:12 ash2k

Hm, I guess what I want is to have a pipeline of many transactions. Can I do that?

ash2k avatar Dec 17 '20 09:12 ash2k

@ash2k no, having multiple transactions in a pipeline is not supported.

vmihailenco avatar Jan 09 '21 08:01 vmihailenco

To achieve that you can use Lua script: https://redis.io/commands/eval to execute multiple operations in single transaction. Since it's treated as single command then you can surround that with pipeline to send multiple commands at once.

lurym avatar Feb 15 '21 15:02 lurym

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Sep 22 '23 00:09 github-actions[bot]