database redis数据库中的HSET和HMSET方法有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/15264480/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between HSET and HMSET method in redis database
提问by sachin
In my application im using redis database.I have gone through their documentation but i couldn't find the difference between HSET and HMSET.
在我的应用程序中,我使用 redis 数据库。我已经阅读了他们的文档,但我找不到 HSET 和 HMSET 之间的区别。
回答by Sergio Tulentsev
HSET used to be able to set only one key-value pair. And if you needed to set several at once, you would have to use HMSET (M for multi). That was changed a few years ago, to allow both commands to accept multiple pairs. And now HMSET is redundant.
HSET 过去只能设置一个键值对。如果您需要一次设置多个,则必须使用 HMSET(M 表示多)。这在几年前发生了变化,以允许两个命令接受多对。现在 HMSET 是多余的。
From official documentation:
来自官方文档:
As per Redis 4.0.0, HMSET is considered deprecated. Please use HSET in new code.
根据 Redis 4.0.0,HMSET 被认为已弃用。请在新代码中使用 HSET。
回答by Hrishikesh Mishra
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.
将存储在键中的散列中的字段设置为值。如果 key 不存在,则创建一个包含散列的新 key。如果字段已存在于哈希中,则将其覆盖。
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.
将指定的字段设置为它们在存储在 key 处的散列中的相应值。此命令会覆盖散列中的任何现有字段。如果 key 不存在,则创建一个包含散列的新密钥。
For more redis commands information, click here.
有关更多 redis 命令信息,请单击此处。
回答by Gunasekar
The only difference between the commands HSETand HMSETis the return valueof the commands. 
HSET return value (Integer reply):
HSET 返回值(整数回复):
- #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.
- #如果该字段是散列中的新字段并且已设置值。(其中- #是创建的新字段数)
- 0 如果该字段已存在于哈希中并且值已更新。
HMSET returns a simple string as a reply.
HMSET 返回一个简单的字符串作为回复。

