Skip to content

Commit 03a8648

Browse files
authored
Backport wrapMultiExec() cmds copy bug fix from v8 (#1823)
1 parent 5fec34b commit 03a8648

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.rdb
22
testdata/*/
3+
.idea/

pipeline_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package redis_test
22

33
import (
4+
"strconv"
5+
46
"github.com/go-redis/redis/v7"
57

68
. "github.com/onsi/ginkgo"
@@ -67,6 +69,21 @@ var _ = Describe("pipelining", func() {
6769
Expect(err).NotTo(HaveOccurred())
6870
Expect(cmds).To(HaveLen(1))
6971
})
72+
73+
It("handles large pipelines", func() {
74+
for callCount := 1; callCount < 16; callCount++ {
75+
for i := 1; i <= callCount; i++ {
76+
pipe.SetNX(strconv.Itoa(i)+"_key", strconv.Itoa(i)+"_value", 0)
77+
}
78+
79+
cmds, err := pipe.Exec()
80+
Expect(err).NotTo(HaveOccurred())
81+
Expect(cmds).To(HaveLen(callCount))
82+
for _, cmd := range cmds {
83+
Expect(cmd).To(BeAssignableToTypeOf(&redis.BoolCmd{}))
84+
}
85+
}
86+
})
7087
}
7188

7289
Describe("Pipeline", func() {

redis.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,11 @@ func wrapMultiExec(cmds []Cmder) []Cmder {
473473
if len(cmds) == 0 {
474474
panic("not reached")
475475
}
476-
cmds = append(cmds, make([]Cmder, 2)...)
477-
copy(cmds[1:], cmds[:len(cmds)-2])
478-
cmds[0] = NewStatusCmd("multi")
479-
cmds[len(cmds)-1] = NewSliceCmd("exec")
480-
return cmds
476+
cmdCopy := make([]Cmder, len(cmds)+2)
477+
cmdCopy[0] = NewStatusCmd("multi")
478+
copy(cmdCopy[1:], cmds)
479+
cmdCopy[len(cmdCopy)-1] = NewSliceCmd("exec")
480+
return cmdCopy
481481
}
482482

483483
func txPipelineReadQueued(rd *proto.Reader, statusCmd *StatusCmd, cmds []Cmder) error {

0 commit comments

Comments
 (0)