ring: return an error in pipeline when all shards are down.

This commit is contained in:
Vladimir Mihailenco 2015-07-13 12:56:16 +03:00
parent 7baacea8fb
commit 54dcf59909
2 changed files with 12 additions and 0 deletions

View File

@ -298,6 +298,9 @@ func (pipe *RingPipeline) Exec() (cmds []Cmder, retErr error) {
name := pipe.ring.hash.Get(hashKey(cmd.clusterKey())) name := pipe.ring.hash.Get(hashKey(cmd.clusterKey()))
if name == "" { if name == "" {
cmd.setErr(errRingShardsDown) cmd.setErr(errRingShardsDown)
if retErr == nil {
retErr = errRingShardsDown
}
continue continue
} }
cmdsMap[name] = append(cmdsMap[name], cmd) cmdsMap[name] = append(cmdsMap[name], cmd)

View File

@ -94,6 +94,15 @@ var _ = Describe("Redis ring", func() {
}) })
Describe("pipelining", func() { Describe("pipelining", func() {
It("returns an error when all shards are down", func() {
ring := redis.NewRing(&redis.RingOptions{})
_, err := ring.Pipelined(func(pipe *redis.RingPipeline) error {
pipe.Ping()
return nil
})
Expect(err).To(MatchError("redis: all ring shards are down"))
})
It("uses both shards", func() { It("uses both shards", func() {
pipe := ring.Pipeline() pipe := ring.Pipeline()
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {