From 5c012a38729f41c0fed43a2975d789ee75f822bd Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 7 Mar 2019 12:19:03 +0200 Subject: [PATCH] Use random node when there are no channels --- cluster.go | 9 ++++++--- cluster_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cluster.go b/cluster.go index e3a6591..c9f1384 100644 --- a/cluster.go +++ b/cluster.go @@ -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 } diff --git a/cluster_test.go b/cluster_test.go index 51633e9..f128a8a 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -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() {