Skip to content

Commit

Permalink
Merge pull request redis#1220 from go-redis/fix/hmset-args
Browse files Browse the repository at this point in the history
Fix HMSet args size
  • Loading branch information
vmihailenco authored Dec 24, 2019
2 parents 0658532 + 071b053 commit 6c240ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
Expand All @@ -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() {
Expand Down

0 comments on commit 6c240ff

Please sign in to comment.