From 4df8b2bbbce4692e4ef5e8335da223804f4fc798 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 15 May 2015 15:11:22 +0300 Subject: [PATCH 1/3] Add ClientPause command. --- commands.go | 7 +++++++ commands_test.go | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index dc68bea1..7f4cbe08 100644 --- a/commands.go +++ b/commands.go @@ -1114,6 +1114,13 @@ func (c *commandable) ClientList() *StringCmd { return cmd } +func (c *commandable) ClientPause(dur time.Duration) *BoolCmd { + cmd := NewBoolCmd("CLIENT", "PAUSE", formatMs(dur)) + cmd._clusterKeyPos = 0 + c.Process(cmd) + return cmd +} + func (c *commandable) ConfigGet(parameter string) *SliceCmd { cmd := NewSliceCmd("CONFIG", "GET", parameter) cmd._clusterKeyPos = 0 diff --git a/commands_test.go b/commands_test.go index c0ab161f..a13ced6c 100644 --- a/commands_test.go +++ b/commands_test.go @@ -18,8 +18,10 @@ var _ = Describe("Commands", func() { BeforeEach(func() { client = redis.NewClient(&redis.Options{ - Addr: redisAddr, - PoolTimeout: 30 * time.Second, + Addr: redisAddr, + ReadTimeout: 100 * time.Millisecond, + WriteTimeout: 100 * time.Millisecond, + PoolTimeout: 30 * time.Second, }) }) @@ -75,6 +77,19 @@ var _ = Describe("Commands", func() { Expect(r.Val()).To(Equal("")) }) + It("should ClientPause", func() { + err := client.ClientPause(time.Second).Err() + Expect(err).NotTo(HaveOccurred()) + + Consistently(func() error { + return client.Ping().Err() + }, "500ms").Should(HaveOccurred()) + + Eventually(func() error { + return client.Ping().Err() + }, "1s").ShouldNot(HaveOccurred()) + }) + It("should ConfigGet", func() { r := client.ConfigGet("*") Expect(r.Err()).NotTo(HaveOccurred()) From bca8659b542abde08f95c20ea679aae373a0fd75 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 18 May 2015 14:43:08 +0300 Subject: [PATCH 2/3] Run tests against latest Redis version. --- commands_test.go | 4 ++-- main_test.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/commands_test.go b/commands_test.go index a13ced6c..dd7c6d66 100644 --- a/commands_test.go +++ b/commands_test.go @@ -273,7 +273,7 @@ var _ = Describe("Commands", func() { }) It("should Migrate", func() { - migrate := client.Migrate("localhost", "6380", "key", 0, 0) + migrate := client.Migrate("localhost", redisSecondaryPort, "key", 0, 0) Expect(migrate.Err()).NotTo(HaveOccurred()) Expect(migrate.Val()).To(Equal("NOKEY")) @@ -281,7 +281,7 @@ var _ = Describe("Commands", func() { Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Val()).To(Equal("OK")) - migrate = client.Migrate("localhost", "6380", "key", 0, 0) + migrate = client.Migrate("localhost", redisSecondaryPort, "key", 0, 0) Expect(migrate.Err()).To(MatchError("IOERR error or timeout writing to target instance")) Expect(migrate.Val()).To(Equal("")) }) diff --git a/main_test.go b/main_test.go index 59032738..57eb4933 100644 --- a/main_test.go +++ b/main_test.go @@ -17,7 +17,11 @@ import ( "gopkg.in/redis.v3" ) -const redisAddr = ":6379" +const ( + redisPort = "6380" + redisAddr = ":" + redisPort + redisSecondaryPort = "6381" +) const ( sentinelName = "mymaster" @@ -27,7 +31,7 @@ const ( sentinelPort = "8126" ) -var sentinelMaster, sentinelSlave1, sentinelSlave2, sentinel *redisProcess +var redisMain, sentinelMaster, sentinelSlave1, sentinelSlave2, sentinel *redisProcess var cluster = &clusterScenario{ ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"}, @@ -39,6 +43,9 @@ var cluster = &clusterScenario{ var _ = BeforeSuite(func() { var err error + redisMain, err = startRedis(redisPort) + Expect(err).NotTo(HaveOccurred()) + sentinelMaster, err = startRedis(sentinelMasterPort) Expect(err).NotTo(HaveOccurred()) @@ -57,6 +64,8 @@ var _ = BeforeSuite(func() { }) var _ = AfterSuite(func() { + Expect(redisMain.Close()).NotTo(HaveOccurred()) + Expect(sentinel.Close()).NotTo(HaveOccurred()) Expect(sentinelSlave1.Close()).NotTo(HaveOccurred()) Expect(sentinelSlave2.Close()).NotTo(HaveOccurred()) From e72b69b964ed7d24381d52266d74436b07792b49 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 18 May 2015 14:52:46 +0300 Subject: [PATCH 3/3] Increase read/write timeout. --- commands_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands_test.go b/commands_test.go index dd7c6d66..7aca5891 100644 --- a/commands_test.go +++ b/commands_test.go @@ -19,8 +19,8 @@ var _ = Describe("Commands", func() { BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, - ReadTimeout: 100 * time.Millisecond, - WriteTimeout: 100 * time.Millisecond, + ReadTimeout: 500 * time.Millisecond, + WriteTimeout: 500 * time.Millisecond, PoolTimeout: 30 * time.Second, }) }) @@ -83,7 +83,7 @@ var _ = Describe("Commands", func() { Consistently(func() error { return client.Ping().Err() - }, "500ms").Should(HaveOccurred()) + }, "900ms").Should(HaveOccurred()) Eventually(func() error { return client.Ping().Err()