1.hset key field value
设置 key 指定的哈希集中指定字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key 关联。如果字段在哈希集中存在,它将被重写。
返回值
整数:含义如下
- 1如果field是一个新的字段
- 0如果field原来在map里面已经存在
返回 key 指定的哈希集中该字段所关联的值
返回值
散值:该字段所关联的值。当字段不存在或者 key 不存在时返回nil。
3.hmset key field value field value-----
设置 key 指定的哈希集中指定字段的值。该命令将重写所有在哈希集中存在的字段。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key 关联
返回值
4.hmget key fielf field
返回 key 指定的哈希集中指定字段的值。
对于哈希集中不存在的每个字段,返回 nil 值。因为不存在的keys被认为是一个空的哈希集,对一个不存在的 key 执行HMGET将返回一个只含有 nil 值的列表
返回值
多个返回值:含有给定字段及其值的列表,并保持与请求相同的顺序。
5.hdel key field field ``````
从 key 指定的哈希集中移除指定的域。在哈希集中不存在的域将被忽略。如果 key 指定的哈希集不存在,它将被认为是一个空的哈希集,该命令将返回0。
返回值
整数:返回从哈希集中成功移除的域的数量,不包括指出但不存在的那些域
历史
6.hexists key field
返回字段是否是 key 指定的哈希集中存在的字段。
返回值
整数, 含义如下:
- 1哈希集中含有该字段。
- 0哈希集中不含有该存在字段,或者key不存在。
7.hgetall key
返回 key 指定的哈希集中所有的字段和值。返回值中,每个字段名的下一个是它的值,所以返回值的长度是哈希集大小的两倍
返回值
多个返回值:哈希集中字段和值的列表。当 key 指定的哈希集不存在时返回空列表。
8.hkeys key
返回 key 指定的哈希集中所有字段的名字。
返回值
多个返回值:哈希集中的字段列表,当 key 指定的哈希集不存在时返回空列表。
9.hlen key
返回 key 指定的哈希集包含的字段的数量。
返回值
整数:哈希集中字段的数量,当 key 指定的哈希集不存在时返回 0
10.hsetnx key field value
只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key 关联。如果字段已存在,该操作无效果。
返回值
整数:含义如下
- 1:如果字段是个新的字段,并成功赋值
- 0:如果哈希集中已存在该字段,没有操作被执行
11.hvals key
返回 key 指定的哈希集中所有字段的值。
返回值
多个返回值:哈希集中的值的列表,当 key 指定的哈希集不存在时返回空列表。
12.hincrby key field increment
增加 key 指定的哈希集中指定字段的数值。如果 key 不存在,会创建一个新的哈希集并与 key 关联。如果字段不存在,则字段的值在该操作执行前被设置为 0
HINCRBY支持的值的范围限定在 64位 有符号整数
返回值
整数:增值操作执行后的该字段的值。
13.hincrbyfloat key field value
Increment the specifiedfieldof an hash stored atkey, and representing a floating point number, by the specifiedincrement. If the field does not exist, it is set to0before performing the operation. An error is returned if one of the following conditions occur:
- The field contains a value of the wrong type (not a string).
- The current field content or the specified increment are not parsable as a double precision floating point number.
The exact behavior of this command is identical to the one of theINCRBYFLOATcommand, please refer to the documentation ofINCRBYFLOATfor further information.
Return value
Bulk reply: the value offieldafter the increment.