mirror of https://github.com/go-redis/redis.git
Support for multi keys in Exists
This commit is contained in:
parent
4cbe497190
commit
7c0cf90fb8
13
commands.go
13
commands.go
|
@ -50,6 +50,8 @@ type Cmdable interface {
|
|||
Unlink(keys ...string) *IntCmd
|
||||
Dump(key string) *StringCmd
|
||||
Exists(key string) *BoolCmd
|
||||
// TODO: merge with Exists in v6
|
||||
ExistsMulti(keys ...string) *IntCmd
|
||||
Expire(key string, expiration time.Duration) *BoolCmd
|
||||
ExpireAt(key string, tm time.Time) *BoolCmd
|
||||
Keys(pattern string) *StringSliceCmd
|
||||
|
@ -317,6 +319,17 @@ func (c *cmdable) Exists(key string) *BoolCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) ExistsMulti(keys ...string) *IntCmd {
|
||||
args := make([]interface{}, 1+len(keys))
|
||||
args[0] = "exists"
|
||||
for i, key := range keys {
|
||||
args[1+i] = key
|
||||
}
|
||||
cmd := NewIntCmd(args...)
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) Expire(key string, expiration time.Duration) *BoolCmd {
|
||||
cmd := NewBoolCmd("expire", key, formatSec(expiration))
|
||||
c.process(cmd)
|
||||
|
|
|
@ -242,6 +242,14 @@ var _ = Describe("Commands", func() {
|
|||
exists = client.Exists("key2")
|
||||
Expect(exists.Err()).NotTo(HaveOccurred())
|
||||
Expect(exists.Val()).To(Equal(false))
|
||||
|
||||
existsMul := client.ExistsMulti("key1", "key2")
|
||||
Expect(existsMul.Err()).NotTo(HaveOccurred())
|
||||
Expect(existsMul.Val()).To(Equal(int64(1)))
|
||||
|
||||
existsMul = client.ExistsMulti("key1", "key1")
|
||||
Expect(existsMul.Err()).NotTo(HaveOccurred())
|
||||
Expect(existsMul.Val()).To(Equal(int64(2)))
|
||||
})
|
||||
|
||||
It("should Expire", func() {
|
||||
|
|
Loading…
Reference in New Issue