What is the difference between HSET and HMSET meth

2019-03-11 14:16发布

In my application im using redis database.I have gone through their documentation but i couldn't find the difference between HSET and HMSET.

3条回答
冷血范
2楼-- · 2019-03-11 14:49

HSET key field value:

Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

HMSET key field value [field value ...]

Sets the specified fields to their respective values in the hash stored at key. This command overwrites any existing fields in the hash. If key does not exist, a new key holding a hash is created.

For more redis commands information, click here.

查看更多
我想做一个坏孩纸
3楼-- · 2019-03-11 15:03

HMSET is like HSET, but it allows multiple field/value pairs to be set at once.

Update

As of now, Oct 2017, HSET in the current redis version (4.0.2 on my machine) can also set multiple key-value pairs.

127.0.0.1:6379> HSET foo a 1 b 2
(integer) 2
127.0.0.1:6379> HGETALL foo
1) "a"
2) "1"
3) "b"
4) "2"

So these commands are now identical.

查看更多
姐就是有狂的资本
4楼-- · 2019-03-11 15:12

The only difference between the commands HSET and HMSET is the return value of the commands.

HSET return value (Integer reply):

  • # if the field is a new field in the hash and value was set. (where # is the number of new fields created )
  • 0 if the field already exists in the hash and the value was updated.

HMSET returns a simple string as a reply.

查看更多
登录 后发表回答