Skip to content

Commit 33c70b2

Browse files
cxljsndyakov
andcommitted
fix: pipeline repeatedly sets the error (#3525)
* fix: pipeline repeatedly sets the error Signed-off-by: Xiaolong Chen <fukua95@gmail.com> * add test Signed-off-by: Xiaolong Chen <fukua95@gmail.com> * CI Signed-off-by: Xiaolong Chen <fukua95@gmail.com> --------- Signed-off-by: Xiaolong Chen <fukua95@gmail.com> Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
1 parent 7706f88 commit 33c70b2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pipeline_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,39 @@ var _ = Describe("pipelining", func() {
6060
Expect(cmds).To(BeEmpty())
6161
})
6262

63+
It("pipeline: basic exec", func() {
64+
p := client.Pipeline()
65+
p.Get(ctx, "key")
66+
p.Set(ctx, "key", "value", 0)
67+
p.Get(ctx, "key")
68+
cmds, err := p.Exec(ctx)
69+
Expect(err).To(Equal(redis.Nil))
70+
Expect(cmds).To(HaveLen(3))
71+
Expect(cmds[0].Err()).To(Equal(redis.Nil))
72+
Expect(cmds[1].(*redis.StatusCmd).Val()).To(Equal("OK"))
73+
Expect(cmds[1].Err()).NotTo(HaveOccurred())
74+
Expect(cmds[2].(*redis.StringCmd).Val()).To(Equal("value"))
75+
Expect(cmds[2].Err()).NotTo(HaveOccurred())
76+
})
77+
78+
It("pipeline: exec pipeline when get conn failed", func() {
79+
p := client.Pipeline()
80+
p.Get(ctx, "key")
81+
p.Set(ctx, "key", "value", 0)
82+
p.Get(ctx, "key")
83+
84+
client.Close()
85+
86+
cmds, err := p.Exec(ctx)
87+
Expect(err).To(Equal(redis.ErrClosed))
88+
Expect(cmds).To(HaveLen(3))
89+
for _, cmd := range cmds {
90+
Expect(cmd.Err()).To(Equal(redis.ErrClosed))
91+
}
92+
93+
client = redis.NewClient(redisOptions())
94+
})
95+
6396
assertPipeline := func() {
6497
It("returns no errors when there are no commands", func() {
6598
_, err := pipe.Exec(ctx)

redis.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,10 @@ func (c *baseClient) generalProcessPipeline(
630630
return err
631631
})
632632
if lastErr == nil || !canRetry || !shouldRetry(lastErr, true) {
633-
setCmdsErr(cmds, lastErr)
633+
// The error should be set here only when failing to obtain the conn.
634+
if !isRedisError(lastErr) {
635+
setCmdsErr(cmds, lastErr)
636+
}
634637
return lastErr
635638
}
636639
}

0 commit comments

Comments
 (0)