Skip to content

Commit 9481d69

Browse files
authored
Merge pull request #1596 from go-redis/fix/tx-pipeline-hook
Fix Tx pipeline hook
2 parents b543ea9 + 76fd0ea commit 9481d69

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cluster.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,10 +1256,13 @@ func (c *ClusterClient) TxPipelined(ctx context.Context, fn func(Pipeliner) erro
12561256
}
12571257

12581258
func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) error {
1259-
return c.hooks.processPipeline(ctx, cmds, c._processTxPipeline)
1259+
return c.hooks.processTxPipeline(ctx, cmds, c._processTxPipeline)
12601260
}
12611261

12621262
func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) error {
1263+
// Trim multi .. exec.
1264+
cmds = cmds[1 : len(cmds)-1]
1265+
12631266
state, err := c.state.Get(ctx)
12641267
if err != nil {
12651268
setCmdsErr(cmds, err)
@@ -1295,6 +1298,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
12951298
if err == nil {
12961299
return
12971300
}
1301+
12981302
if attempt < c.opt.MaxRedirects {
12991303
if err := c.mapCmdsByNode(ctx, failedCmds, cmds); err != nil {
13001304
setCmdsErr(cmds, err)

cluster_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,14 +820,14 @@ var _ = Describe("ClusterClient", func() {
820820

821821
client.AddHook(&hook{
822822
beforeProcessPipeline: func(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
823-
Expect(cmds).To(HaveLen(1))
824-
Expect(cmds[0].String()).To(Equal("ping: "))
823+
Expect(cmds).To(HaveLen(3))
824+
Expect(cmds[1].String()).To(Equal("ping: "))
825825
stack = append(stack, "cluster.BeforeProcessPipeline")
826826
return ctx, nil
827827
},
828828
afterProcessPipeline: func(ctx context.Context, cmds []redis.Cmder) error {
829-
Expect(cmds).To(HaveLen(1))
830-
Expect(cmds[0].String()).To(Equal("ping: PONG"))
829+
Expect(cmds).To(HaveLen(3))
830+
Expect(cmds[1].String()).To(Equal("ping: PONG"))
831831
stack = append(stack, "cluster.AfterProcessPipeline")
832832
return nil
833833
},

internal/pool/pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ func (p *ConnPool) ReapStaleConns() (int, error) {
477477
p.connsMu.Lock()
478478
cn := p.reapStaleConn()
479479
p.connsMu.Unlock()
480+
480481
p.freeTurn()
481482

482483
if cn != nil {

0 commit comments

Comments
 (0)