Replace Exists with ExistsMulti.

This commit is contained in:
Vladimir Mihailenco 2017-02-18 16:32:39 +02:00
parent 56ddaf1199
commit d95ce53b0d
2 changed files with 23 additions and 31 deletions

View File

@ -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 {

View File

@ -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())