Skip to content

Commit 6c240ff

Browse files
authored
Merge pull request #1220 from go-redis/fix/hmset-args
Fix HMSet args size
2 parents 0658532 + 071b053 commit 6c240ff

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ func (c cmdable) HMGet(key string, fields ...string) *SliceCmd {
988988
//
989989
// Note that it uses HSET Redis command underneath because HMSET is deprecated.
990990
func (c cmdable) HMSet(key string, values ...interface{}) *IntCmd {
991-
args := make([]interface{}, 2+2*len(values))
991+
args := make([]interface{}, 2, 2+len(values))
992992
args[0] = "hset"
993993
args[1] = key
994994
args = appendArgs(args, values)

commands_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,9 +1367,7 @@ var _ = Describe("Commands", func() {
13671367
})
13681368

13691369
It("should HMGet", func() {
1370-
err := client.HSet("hash", "key1", "hello1").Err()
1371-
Expect(err).NotTo(HaveOccurred())
1372-
err = client.HSet("hash", "key2", "hello2").Err()
1370+
err := client.HMSet("hash", "key1", "hello1", "key2", "hello2").Err()
13731371
Expect(err).NotTo(HaveOccurred())
13741372

13751373
vals, err := client.HMGet("hash", "key1", "key2", "_").Result()
@@ -1383,7 +1381,7 @@ var _ = Describe("Commands", func() {
13831381
"key2": "hello2",
13841382
}).Result()
13851383
Expect(err).NotTo(HaveOccurred())
1386-
Expect(ok).To(Equal(int64(3)))
1384+
Expect(ok).To(Equal(int64(2)))
13871385

13881386
v, err := client.HGet("hash", "key1").Result()
13891387
Expect(err).NotTo(HaveOccurred())
@@ -1392,6 +1390,10 @@ var _ = Describe("Commands", func() {
13921390
v, err = client.HGet("hash", "key2").Result()
13931391
Expect(err).NotTo(HaveOccurred())
13941392
Expect(v).To(Equal("hello2"))
1393+
1394+
keys, err := client.HKeys("hash").Result()
1395+
Expect(err).NotTo(HaveOccurred())
1396+
Expect(keys).To(ConsistOf([]string{"key1", "key2"}))
13951397
})
13961398

13971399
It("should HSet", func() {

0 commit comments

Comments
 (0)