From c86c141c389296f6b279ccebc75b7594a3f7f1fb Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 23 Feb 2017 15:29:38 +0200 Subject: [PATCH 1/2] Use simple PING for compatibility --- pubsub.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubsub.go b/pubsub.go index f98566e8..6c182296 100644 --- a/pubsub.go +++ b/pubsub.go @@ -98,10 +98,10 @@ func (c *PubSub) Close() error { return c.base.Close() } -func (c *PubSub) Ping(payload string) error { +func (c *PubSub) Ping(payload ...string) error { args := []interface{}{"PING"} - if payload != "" { - args = append(args, payload) + if len(payload) == 1 { + args = append(args, payload[0]) } cmd := NewCmd(args...) @@ -239,7 +239,7 @@ func (c *PubSub) receiveMessage(timeout time.Duration) (*Message, error) { errNum++ if errNum < 3 { if netErr, ok := err.(net.Error); ok && netErr.Timeout() { - err := c.Ping("hello") + err := c.Ping() if err != nil { internal.Logf("PubSub.Ping failed: %s", err) } From 892fb8d573f4e03aabc53100df0473a24ace8516 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Fri, 24 Feb 2017 18:03:21 +0900 Subject: [PATCH 2/2] the timeout of WAIT command is in milliseconds. --- commands.go | 2 +- commands_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index bc93df9f..e2dc0caa 100644 --- a/commands.go +++ b/commands.go @@ -275,7 +275,7 @@ func (c *cmdable) Ping() *StatusCmd { func (c *cmdable) Wait(numSlaves int, timeout time.Duration) *IntCmd { - cmd := NewIntCmd("wait", numSlaves, int(timeout/time.Second)) + cmd := NewIntCmd("wait", numSlaves, int(timeout/time.Millisecond)) c.process(cmd) return cmd } diff --git a/commands_test.go b/commands_test.go index a524aafc..7e4182e6 100644 --- a/commands_test.go +++ b/commands_test.go @@ -52,9 +52,11 @@ var _ = Describe("Commands", func() { It("should Wait", func() { // assume testing on single redis instance - wait := client.Wait(0, time.Minute) + start := time.Now() + wait := client.Wait(1, time.Second) Expect(wait.Err()).NotTo(HaveOccurred()) Expect(wait.Val()).To(Equal(int64(0))) + Expect(time.Now()).To(BeTemporally("~", start.Add(time.Second), 800*time.Millisecond)) }) It("should Select", func() {