diff --git a/commands.go b/commands.go index c4b9d94..cf61c20 100644 --- a/commands.go +++ b/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) diff --git a/commands_test.go b/commands_test.go index eb0d523..576389d 100644 --- a/commands_test.go +++ b/commands_test.go @@ -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())