forked from mirror/redis
Replace Exists with ExistsMulti.
This commit is contained in:
parent
56ddaf1199
commit
d95ce53b0d
12
commands.go
12
commands.go
|
@ -49,9 +49,7 @@ type Cmdable interface {
|
||||||
Del(keys ...string) *IntCmd
|
Del(keys ...string) *IntCmd
|
||||||
Unlink(keys ...string) *IntCmd
|
Unlink(keys ...string) *IntCmd
|
||||||
Dump(key string) *StringCmd
|
Dump(key string) *StringCmd
|
||||||
Exists(key string) *BoolCmd
|
Exists(keys ...string) *IntCmd
|
||||||
// TODO: merge with Exists in v6
|
|
||||||
ExistsMulti(keys ...string) *IntCmd
|
|
||||||
Expire(key string, expiration time.Duration) *BoolCmd
|
Expire(key string, expiration time.Duration) *BoolCmd
|
||||||
ExpireAt(key string, tm time.Time) *BoolCmd
|
ExpireAt(key string, tm time.Time) *BoolCmd
|
||||||
Keys(pattern string) *StringSliceCmd
|
Keys(pattern string) *StringSliceCmd
|
||||||
|
@ -320,13 +318,7 @@ func (c *cmdable) Dump(key string) *StringCmd {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmdable) Exists(key string) *BoolCmd {
|
func (c *cmdable) Exists(keys ...string) *IntCmd {
|
||||||
cmd := NewBoolCmd("exists", key)
|
|
||||||
c.process(cmd)
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cmdable) ExistsMulti(keys ...string) *IntCmd {
|
|
||||||
args := make([]interface{}, 1+len(keys))
|
args := make([]interface{}, 1+len(keys))
|
||||||
args[0] = "exists"
|
args[0] = "exists"
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
|
|
|
@ -242,21 +242,21 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(set.Err()).NotTo(HaveOccurred())
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
Expect(set.Val()).To(Equal("OK"))
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
exists := client.Exists("key1")
|
n, err := client.Exists("key1").Result()
|
||||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(exists.Val()).To(Equal(true))
|
Expect(n).To(Equal(int64(1)))
|
||||||
|
|
||||||
exists = client.Exists("key2")
|
n, err = client.Exists("key2").Result()
|
||||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(exists.Val()).To(Equal(false))
|
Expect(n).To(Equal(int64(0)))
|
||||||
|
|
||||||
existsMul := client.ExistsMulti("key1", "key2")
|
n, err = client.Exists("key1", "key2").Result()
|
||||||
Expect(existsMul.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(existsMul.Val()).To(Equal(int64(1)))
|
Expect(n).To(Equal(int64(1)))
|
||||||
|
|
||||||
existsMul = client.ExistsMulti("key1", "key1")
|
n, err = client.Exists("key1", "key1").Result()
|
||||||
Expect(existsMul.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(existsMul.Val()).To(Equal(int64(2)))
|
Expect(n).To(Equal(int64(2)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should Expire", func() {
|
It("should Expire", func() {
|
||||||
|
@ -286,17 +286,17 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(set.Err()).NotTo(HaveOccurred())
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
Expect(set.Val()).To(Equal("OK"))
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
exists := client.Exists("key")
|
n, err := client.Exists("key").Result()
|
||||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(exists.Val()).To(Equal(true))
|
Expect(n).To(Equal(int64(1)))
|
||||||
|
|
||||||
expireAt := client.ExpireAt("key", time.Now().Add(-time.Hour))
|
expireAt := client.ExpireAt("key", time.Now().Add(-time.Hour))
|
||||||
Expect(expireAt.Err()).NotTo(HaveOccurred())
|
Expect(expireAt.Err()).NotTo(HaveOccurred())
|
||||||
Expect(expireAt.Val()).To(Equal(true))
|
Expect(expireAt.Val()).To(Equal(true))
|
||||||
|
|
||||||
exists = client.Exists("key")
|
n, err = client.Exists("key").Result()
|
||||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(exists.Val()).To(Equal(false))
|
Expect(n).To(Equal(int64(0)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should Keys", func() {
|
It("should Keys", func() {
|
||||||
|
@ -675,9 +675,9 @@ var _ = Describe("Commands", func() {
|
||||||
Describe("strings", func() {
|
Describe("strings", func() {
|
||||||
|
|
||||||
It("should Append", func() {
|
It("should Append", func() {
|
||||||
exists := client.Exists("key")
|
n, err := client.Exists("key").Result()
|
||||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(exists.Val()).To(Equal(false))
|
Expect(n).To(Equal(int64(0)))
|
||||||
|
|
||||||
append := client.Append("key", "Hello")
|
append := client.Append("key", "Hello")
|
||||||
Expect(append.Err()).NotTo(HaveOccurred())
|
Expect(append.Err()).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue