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
Quit() *StatusCmd
Del(keys ...string) *IntCmd
Unlink(keys ...string) *IntCmd
Dump(key string) *StringCmd
Exists(key string) *BoolCmd
Expire(key string, expiration time.Duration) *BoolCmd
@ -292,6 +293,17 @@ func (c *cmdable) Del(keys ...string) *IntCmd {
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 {
cmd := NewStringCmd("dump", key)
c.process(cmd)

View File

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