redis基本数据类型 hash类型

一、特点

        hash是一个string类型的field和value的映射表,特别适合用于存储对象。如果hash的属性值被删除完,那么hash的key也会被redis删除。hash结构是可以压缩的,相比较N多个字段都单独存储成string类型来说,会比较节省内存。

二、操作

 1)HDEL key field [field ...]        删除一个或多个哈希字段

summary: Delete one or more hash fields
since: 2.0.0

2)HEXISTS key field        确定一个哈希字段是否存在

summary: Determine if a hash field exists

since: 2.0.0

3)HGET key field        获取一个哈希字段的值

summary: Get the value of a hash field        
since: 2.0.0

4)HGETALL key        获取散列中的所有字段和值

summary: Get all the fields and values in a hash
since: 2.0.0

5)HINCRBY key field increment        将哈希字段的整数值增加给定的数字

summary: Increment the integer value of a hash field by the given number
since: 2.0.0

6)HINCRBYFLOAT key field increment        将哈希字段的浮点值增加给定的数量

summary: Increment the float value of a hash field by the given amount
since: 2.6.0

7)HKEYS key        获取一个散列中的所有字段

summary: Get all the fields in a hash

since: 2.0.0

8)HLEN key        获取一个散列中的字段数

summary: Get the number of fields in a hash
since: 2.0.0

9)HMGET key field [field ...]        获取所有给定哈希字段的值

summary: Get the values of all the given hash fields
since: 2.0.0

10)HMSET key field value [field value ...]        将多个哈希字段设置为多个值

summary: Set multiple hash fields to multiple values
since: 2.0.0

11)HRANDFIELD key [count [WITHVALUES]]        从散列中获取一个或多个随机字段

summary: Get one or multiple random fields from a hash
since: 6.2.0

12)HSCAN key cursor [MATCH pattern] [COUNT count]        递增迭代哈希字段和相关值

summary: Incrementally iterate hash fields and associated values
since: 2.8.0

13)HSET key field value [field value ...]        设置哈希字段的字符串值

summary: Set the string value of a hash field
since: 2.0.0

14)HSETNX key field value        仅当一个哈希字段不存在时,设置该字段的值    

summary: Set the value of a hash field, only if the field does not exist
since: 2.0.0

15)HSTRLEN key field        获取哈希字段值的长度

summary: Get the length of the value of a hash field
since: 3.2.0

16)HVALS key        获取哈希中的所有值

summary: Get all the values in a hash

since: 2.0.0

三、应用场景

1、购物车  ==》id为key,商品id为field,商品数量为value

2、存储对象 key-value

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值