From d95ce53b0de76684a6d3fc0263e3c97a33087c23 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 18 Feb 2017 16:32:39 +0200 Subject: [PATCH] Replace Exists with ExistsMulti. --- commands.go | 12 ++---------- commands_test.go | 42 +++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/commands.go b/commands.go index 21d5aa9..9fcfadc 100644 --- a/commands.go +++ b/commands.go @@ -49,9 +49,7 @@ type Cmdable interface { Del(keys ...string) *IntCmd Unlink(keys ...string) *IntCmd Dump(key string) *StringCmd - Exists(key string) *BoolCmd - // TODO: merge with Exists in v6 - ExistsMulti(keys ...string) *IntCmd + Exists(keys ...string) *IntCmd Expire(key string, expiration time.Duration) *BoolCmd ExpireAt(key string, tm time.Time) *BoolCmd Keys(pattern string) *StringSliceCmd @@ -320,13 +318,7 @@ func (c *cmdable) Dump(key string) *StringCmd { return cmd } -func (c *cmdable) Exists(key string) *BoolCmd { - cmd := NewBoolCmd("exists", key) - c.process(cmd) - return cmd -} - -func (c *cmdable) ExistsMulti(keys ...string) *IntCmd { +func (c *cmdable) Exists(keys ...string) *IntCmd { args := make([]interface{}, 1+len(keys)) args[0] = "exists" for i, key := range keys { diff --git a/commands_test.go b/commands_test.go index 2619186..29d6cb6 100644 --- a/commands_test.go +++ b/commands_test.go @@ -242,21 +242,21 @@ var _ = Describe("Commands", func() { Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Val()).To(Equal("OK")) - exists := client.Exists("key1") - Expect(exists.Err()).NotTo(HaveOccurred()) - Expect(exists.Val()).To(Equal(true)) + n, err := client.Exists("key1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(1))) - exists = client.Exists("key2") - Expect(exists.Err()).NotTo(HaveOccurred()) - Expect(exists.Val()).To(Equal(false)) + n, err = client.Exists("key2").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(0))) - existsMul := client.ExistsMulti("key1", "key2") - Expect(existsMul.Err()).NotTo(HaveOccurred()) - Expect(existsMul.Val()).To(Equal(int64(1))) + n, err = client.Exists("key1", "key2").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(1))) - existsMul = client.ExistsMulti("key1", "key1") - Expect(existsMul.Err()).NotTo(HaveOccurred()) - Expect(existsMul.Val()).To(Equal(int64(2))) + n, err = client.Exists("key1", "key1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(2))) }) It("should Expire", func() { @@ -286,17 +286,17 @@ var _ = Describe("Commands", func() { Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Val()).To(Equal("OK")) - exists := client.Exists("key") - Expect(exists.Err()).NotTo(HaveOccurred()) - Expect(exists.Val()).To(Equal(true)) + n, err := client.Exists("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(1))) expireAt := client.ExpireAt("key", time.Now().Add(-time.Hour)) Expect(expireAt.Err()).NotTo(HaveOccurred()) Expect(expireAt.Val()).To(Equal(true)) - exists = client.Exists("key") - Expect(exists.Err()).NotTo(HaveOccurred()) - Expect(exists.Val()).To(Equal(false)) + n, err = client.Exists("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(0))) }) It("should Keys", func() { @@ -675,9 +675,9 @@ var _ = Describe("Commands", func() { Describe("strings", func() { It("should Append", func() { - exists := client.Exists("key") - Expect(exists.Err()).NotTo(HaveOccurred()) - Expect(exists.Val()).To(Equal(false)) + n, err := client.Exists("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(0))) append := client.Append("key", "Hello") Expect(append.Err()).NotTo(HaveOccurred())