重学redis系列之hash

150 阅读1分钟

redis所支持的数据结构之一hash,类似我们常用的数据结构map,同样的,可以通过使用help @hash查看其命名的使用帮助。 在这里插入图片描述 向hash中设置一个值,语法如下: HSET key field value summary: Set the string value of a hash field 在这里插入图片描述

同时也可以向一个hash中设置多个键值对: 在这里插入图片描述

有设置就有对应的获取:

HGET key field summary: Get the value of a hash field

在这里插入图片描述

也可以一次获取多个字段:

在这里插入图片描述

可以获取一个hash的所有字段: HKEYS key summary: Get all the fields in a hash 在这里插入图片描述

也可以获取一个hash的所有值:

在这里插入图片描述

还可以一次获取该hash所有的key-value:

HGETALL key summary: Get all the fields and values in a hash

在这里插入图片描述

同样可以获取一个hash的字段数: HLEN key summary: Get the number of fields in a hash

在这里插入图片描述

获取一个hash中某字段值的长度:

HSTRLEN key field summary: Get the length of the value of a hash field 在这里插入图片描述

还可以对值为数字的字段进行加减操作: HINCRBY key field increment summary: Increment the integer value of a hash field by the given number HINCRBYFLOAT key field increment summary: Increment the float value of a hash field by the given amount

在这里插入图片描述

当然也可以删除一个hash的一个或多个字段(以及其对应的值):

HDEL key field [field ...] summary: Delete one or more hash fields 在这里插入图片描述

关于hash的命令差不多也就介绍完了,到此为止。