Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't return an error when pipeline is empty #573

Merged
merged 1 commit into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package redis

import (
"errors"
"sync"

"github.com/go-redis/redis/internal/pool"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (c *Pipeline) Exec() ([]Cmder, error) {
}

if len(c.cmds) == 0 {
return nil, errors.New("redis: pipeline is empty")
return nil, nil
}

cmds := c.cmds
Expand Down
9 changes: 5 additions & 4 deletions pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ var _ = Describe("pipelining", func() {
})

assertPipeline := func() {
It("returns an error when there are no commands", func() {
It("returns no errors when there are no commands", func() {
_, err := pipe.Exec()
Expect(err).To(MatchError("redis: pipeline is empty"))
Expect(err).NotTo(HaveOccurred())
})

It("discards queued commands", func() {
pipe.Get("key")
pipe.Discard()
_, err := pipe.Exec()
Expect(err).To(MatchError("redis: pipeline is empty"))
cmds, err := pipe.Exec()
Expect(err).NotTo(HaveOccurred())
Expect(cmds).To(BeNil())
})

It("handles val/err", func() {
Expand Down
1 change: 1 addition & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ var _ = Describe("Client OnConnect", func() {

BeforeEach(func() {
opt := redisOptions()
opt.DB = 0
opt.OnConnect = func(cn *redis.Conn) error {
return cn.ClientSetName("on_connect").Err()
}
Expand Down
4 changes: 2 additions & 2 deletions tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ var _ = Describe("Tx", func() {
Expect(get.Val()).To(Equal("hello2"))
})

It("returns an error when there are no commands", func() {
It("returns no error when there are no commands", func() {
err := client.Watch(func(tx *redis.Tx) error {
_, err := tx.Pipelined(func(redis.Pipeliner) error { return nil })
return err
})
Expect(err).To(MatchError("redis: pipeline is empty"))
Expect(err).NotTo(HaveOccurred())

v, err := client.Ping().Result()
Expect(err).NotTo(HaveOccurred())
Expand Down