Skip to content

Commit

Permalink
Use random node when there are no channels
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 7, 2019
1 parent b665d8f commit 5c012a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,13 @@ func (c *ClusterClient) pubSub() *PubSub {
panic("node != nil")
}

slot := hashtag.Slot(channels[0])

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 {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ var _ = Describe("ClusterClient", func() {
return nil
}, 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() {
Expand Down

0 comments on commit 5c012a3

Please sign in to comment.