Merge pull request #987 from go-redis/fix/channels-random-node

Use random node when there are no channels
This commit is contained in:
Vladimir Mihailenco 2019-03-07 14:31:53 +02:00 committed by GitHub
commit 0d39ee8976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -1537,10 +1537,13 @@ func (c *ClusterClient) pubSub() *PubSub {
panic("node != nil") panic("node != nil")
} }
slot := hashtag.Slot(channels[0])
var err error var err error
node, err = c.slotMasterNode(slot) if len(channels) > 0 {
slot := hashtag.Slot(channels[0])
node, err = c.slotMasterNode(slot)
} else {
node, err = c.nodes.Random()
}
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -512,6 +512,14 @@ var _ = Describe("ClusterClient", func() {
return nil return nil
}, 30*time.Second).ShouldNot(HaveOccurred()) }, 30*time.Second).ShouldNot(HaveOccurred())
}) })
It("supports PubSub.Ping without channels", func() {
pubsub := client.Subscribe()
defer pubsub.Close()
err := pubsub.Ping()
Expect(err).NotTo(HaveOccurred())
})
} }
Describe("ClusterClient", func() { Describe("ClusterClient", func() {