Merge pull request #462 from go-redis/fix/unlink

Add unlink command.
This commit is contained in:
Vladimir Mihailenco 2016-12-22 14:50:47 +02:00 committed by GitHub
commit b7bae3a780
2 changed files with 30 additions and 9 deletions

View File

@ -47,6 +47,7 @@ type Cmdable interface {
Ping() *StatusCmd Ping() *StatusCmd
Quit() *StatusCmd Quit() *StatusCmd
Del(keys ...string) *IntCmd Del(keys ...string) *IntCmd
Unlink(keys ...string) *IntCmd
Dump(key string) *StringCmd Dump(key string) *StringCmd
Exists(key string) *BoolCmd Exists(key string) *BoolCmd
Expire(key string, expiration time.Duration) *BoolCmd Expire(key string, expiration time.Duration) *BoolCmd
@ -292,6 +293,17 @@ func (c *cmdable) Del(keys ...string) *IntCmd {
return cmd return cmd
} }
func (c *cmdable) Unlink(keys ...string) *IntCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "unlink"
for i, key := range keys {
args[1+i] = key
}
cmd := NewIntCmd(args...)
c.process(cmd)
return cmd
}
func (c *cmdable) Dump(key string) *StringCmd { func (c *cmdable) Dump(key string) *StringCmd {
cmd := NewStringCmd("dump", key) cmd := NewStringCmd("dump", key)
c.process(cmd) c.process(cmd)

View File

@ -199,16 +199,25 @@ var _ = Describe("Commands", func() {
Describe("keys", func() { Describe("keys", func() {
It("should Del", func() { It("should Del", func() {
set := client.Set("key1", "Hello", 0) err := client.Set("key1", "Hello", 0).Err()
Expect(set.Err()).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK")) err = client.Set("key2", "World", 0).Err()
set = client.Set("key2", "World", 0) Expect(err).NotTo(HaveOccurred())
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
del := client.Del("key1", "key2", "key3") n, err := client.Del("key1", "key2", "key3").Result()
Expect(del.Err()).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(del.Val()).To(Equal(int64(2))) Expect(n).To(Equal(int64(2)))
})
It("should Unlink", func() {
err := client.Set("key1", "Hello", 0).Err()
Expect(err).NotTo(HaveOccurred())
err = client.Set("key2", "World", 0).Err()
Expect(err).NotTo(HaveOccurred())
n, err := client.Unlink("key1", "key2", "key3").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(2)))
}) })
It("should Dump", func() { It("should Dump", func() {