From 071b053eddb3d2196476a382abc6680fadfc47aa Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 24 Dec 2019 12:23:32 +0200 Subject: [PATCH] Fix HMSet args size --- commands.go | 2 +- commands_test.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 0a6d1ad..a41a969 100644 --- a/commands.go +++ b/commands.go @@ -988,7 +988,7 @@ func (c cmdable) HMGet(key string, fields ...string) *SliceCmd { // // Note that it uses HSET Redis command underneath because HMSET is deprecated. func (c cmdable) HMSet(key string, values ...interface{}) *IntCmd { - args := make([]interface{}, 2+2*len(values)) + args := make([]interface{}, 2, 2+len(values)) args[0] = "hset" args[1] = key args = appendArgs(args, values) diff --git a/commands_test.go b/commands_test.go index e135589..57b6ad0 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1367,9 +1367,7 @@ var _ = Describe("Commands", func() { }) It("should HMGet", func() { - err := client.HSet("hash", "key1", "hello1").Err() - Expect(err).NotTo(HaveOccurred()) - err = client.HSet("hash", "key2", "hello2").Err() + err := client.HMSet("hash", "key1", "hello1", "key2", "hello2").Err() Expect(err).NotTo(HaveOccurred()) vals, err := client.HMGet("hash", "key1", "key2", "_").Result() @@ -1383,7 +1381,7 @@ var _ = Describe("Commands", func() { "key2": "hello2", }).Result() Expect(err).NotTo(HaveOccurred()) - Expect(ok).To(Equal(int64(3))) + Expect(ok).To(Equal(int64(2))) v, err := client.HGet("hash", "key1").Result() Expect(err).NotTo(HaveOccurred()) @@ -1392,6 +1390,10 @@ var _ = Describe("Commands", func() { v, err = client.HGet("hash", "key2").Result() Expect(err).NotTo(HaveOccurred()) Expect(v).To(Equal("hello2")) + + keys, err := client.HKeys("hash").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(keys).To(ConsistOf([]string{"key1", "key2"})) }) It("should HSet", func() {