forked from mirror/redis
commit
5183f8dcde
15
commands.go
15
commands.go
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue