Skip to content

Commit

Permalink
Backport wrapMultiExec() cmds copy bug fix from v8 (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
wspowell committed Jul 16, 2021
1 parent 5fec34b commit 03a8648
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.rdb
testdata/*/
.idea/
17 changes: 17 additions & 0 deletions pipeline_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package redis_test

import (
"strconv"

"github.com/go-redis/redis/v7"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -67,6 +69,21 @@ var _ = Describe("pipelining", func() {
Expect(err).NotTo(HaveOccurred())
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() {
Expand Down
10 changes: 5 additions & 5 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ func wrapMultiExec(cmds []Cmder) []Cmder {
if len(cmds) == 0 {
panic("not reached")
}
cmds = append(cmds, make([]Cmder, 2)...)
copy(cmds[1:], cmds[:len(cmds)-2])
cmds[0] = NewStatusCmd("multi")
cmds[len(cmds)-1] = NewSliceCmd("exec")
return cmds
cmdCopy := make([]Cmder, len(cmds)+2)
cmdCopy[0] = NewStatusCmd("multi")
copy(cmdCopy[1:], cmds)
cmdCopy[len(cmdCopy)-1] = NewSliceCmd("exec")
return cmdCopy
}

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

0 comments on commit 03a8648

Please sign in to comment.