Backport wrapMultiExec() cmds copy bug fix from v8 (#1823)

This commit is contained in:
Wesley Powell 2021-07-16 02:41:17 -05:00 committed by GitHub
parent 5fec34b901
commit 03a86486ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.rdb *.rdb
testdata/*/ testdata/*/
.idea/

View File

@ -1,6 +1,8 @@
package redis_test package redis_test
import ( import (
"strconv"
"github.com/go-redis/redis/v7" "github.com/go-redis/redis/v7"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -67,6 +69,21 @@ var _ = Describe("pipelining", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(cmds).To(HaveLen(1)) Expect(cmds).To(HaveLen(1))
}) })
It("handles large pipelines", func() {
for callCount := 1; callCount < 16; callCount++ {
for i := 1; i <= callCount; i++ {
pipe.SetNX(strconv.Itoa(i)+"_key", strconv.Itoa(i)+"_value", 0)
}
cmds, err := pipe.Exec()
Expect(err).NotTo(HaveOccurred())
Expect(cmds).To(HaveLen(callCount))
for _, cmd := range cmds {
Expect(cmd).To(BeAssignableToTypeOf(&redis.BoolCmd{}))
}
}
})
} }
Describe("Pipeline", func() { Describe("Pipeline", func() {

View File

@ -473,11 +473,11 @@ func wrapMultiExec(cmds []Cmder) []Cmder {
if len(cmds) == 0 { if len(cmds) == 0 {
panic("not reached") panic("not reached")
} }
cmds = append(cmds, make([]Cmder, 2)...) cmdCopy := make([]Cmder, len(cmds)+2)
copy(cmds[1:], cmds[:len(cmds)-2]) cmdCopy[0] = NewStatusCmd("multi")
cmds[0] = NewStatusCmd("multi") copy(cmdCopy[1:], cmds)
cmds[len(cmds)-1] = NewSliceCmd("exec") cmdCopy[len(cmdCopy)-1] = NewSliceCmd("exec")
return cmds return cmdCopy
} }
func txPipelineReadQueued(rd *proto.Reader, statusCmd *StatusCmd, cmds []Cmder) error { func txPipelineReadQueued(rd *proto.Reader, statusCmd *StatusCmd, cmds []Cmder) error {