Merge pull request #314 from go-redis/feature/HMSetMap

Add HMSetMap.
This commit is contained in:
Vladimir Mihailenco 2016-05-02 14:39:45 +03:00
commit 5183f8dcde
2 changed files with 32 additions and 0 deletions

View File

@ -696,6 +696,21 @@ func (c *commandable) HMSet(key, field, value string, pairs ...string) *StatusCm
return cmd
}
func (c *commandable) HMSetMap(key string, fields map[string]string) *StatusCmd {
args := make([]interface{}, 2+len(fields)*2)
args[0] = "HMSET"
args[1] = key
i := 2
for k, v := range fields {
args[i] = k
args[i+1] = v
i += 2
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) HSet(key, field, value string) *BoolCmd {
cmd := NewBoolCmd("HSET", key, field, value)
c.Process(cmd)

View File

@ -1195,6 +1195,23 @@ var _ = Describe("Commands", func() {
Expect(hGet.Val()).To(Equal("hello2"))
})
It("should HMSetMap", func() {
hMSetMap := client.HMSetMap("hash", map[string]string{
"key3": "hello3",
"key4": "hello4",
})
Expect(hMSetMap.Err()).NotTo(HaveOccurred())
Expect(hMSetMap.Val()).To(Equal("OK"))
hGet := client.HGet("hash", "key3")
Expect(hGet.Err()).NotTo(HaveOccurred())
Expect(hGet.Val()).To(Equal("hello3"))
hGet = client.HGet("hash", "key4")
Expect(hGet.Err()).NotTo(HaveOccurred())
Expect(hGet.Val()).To(Equal("hello4"))
})
It("should HSet", func() {
hSet := client.HSet("hash", "key", "hello")
Expect(hSet.Err()).NotTo(HaveOccurred())