forked from mirror/redis
Don't return an error when pipeline is empty
This commit is contained in:
parent
ee42c3d5d3
commit
f60bce9166
|
@ -1,7 +1,6 @@
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/go-redis/redis/internal/pool"
|
"github.com/go-redis/redis/internal/pool"
|
||||||
|
@ -80,7 +79,7 @@ func (c *Pipeline) Exec() ([]Cmder, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.cmds) == 0 {
|
if len(c.cmds) == 0 {
|
||||||
return nil, errors.New("redis: pipeline is empty")
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds := c.cmds
|
cmds := c.cmds
|
||||||
|
|
|
@ -34,16 +34,17 @@ var _ = Describe("pipelining", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
assertPipeline := 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()
|
_, err := pipe.Exec()
|
||||||
Expect(err).To(MatchError("redis: pipeline is empty"))
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("discards queued commands", func() {
|
It("discards queued commands", func() {
|
||||||
pipe.Get("key")
|
pipe.Get("key")
|
||||||
pipe.Discard()
|
pipe.Discard()
|
||||||
_, err := pipe.Exec()
|
cmds, err := pipe.Exec()
|
||||||
Expect(err).To(MatchError("redis: pipeline is empty"))
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(cmds).To(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("handles val/err", func() {
|
It("handles val/err", func() {
|
||||||
|
|
|
@ -344,6 +344,7 @@ var _ = Describe("Client OnConnect", func() {
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
opt := redisOptions()
|
opt := redisOptions()
|
||||||
|
opt.DB = 0
|
||||||
opt.OnConnect = func(cn *redis.Conn) error {
|
opt.OnConnect = func(cn *redis.Conn) error {
|
||||||
return cn.ClientSetName("on_connect").Err()
|
return cn.ClientSetName("on_connect").Err()
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,12 +86,12 @@ var _ = Describe("Tx", func() {
|
||||||
Expect(get.Val()).To(Equal("hello2"))
|
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 := client.Watch(func(tx *redis.Tx) error {
|
||||||
_, err := tx.Pipelined(func(redis.Pipeliner) error { return nil })
|
_, err := tx.Pipelined(func(redis.Pipeliner) error { return nil })
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
Expect(err).To(MatchError("redis: pipeline is empty"))
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
v, err := client.Ping().Result()
|
v, err := client.Ping().Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue