12. Redis哈希(Hash)
12. Redis哈希(Hash)
double大宝 发表于12个月前
12. Redis哈希(Hash)
  • 发表于 12个月前
  • 阅读 6
  • 收藏 0
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

KV模式不变,但V是一个键值对

 hset/hget/hmset/hmget/hgetall/hdel
 hlen
 hexists key 在key里面的某个值的key
 hkeys/hvals
 hincrby/hincrbyfloat
 hsetnx

127.0.0.1:6379> HSET user id 11
(integer) 1
127.0.0.1:6379> HGET user id
"11"
127.0.0.1:6379> HSET user name z3
(integer) 1
127.0.0.1:6379> HGET user name
"z3"
127.0.0.1:6379> HMSET customer id 11 name wgy age 26
OK
127.0.0.1:6379> HMGET customer id name age
1) "11"
2) "wgy"
3) "26"
127.0.0.1:6379> HGETALL customer
1) "id"
2) "11"
3) "name"
4) "wgy"
5) "age"
6) "26"
127.0.0.1:6379> HDEL user
(error) ERR wrong number of arguments for 'hdel' command
127.0.0.1:6379> HDEL user name
(integer) 1
127.0.0.1:6379> HLEN user
(integer) 1
127.0.0.1:6379> HLEN customer
(integer) 3
127.0.0.1:6379> HEXISTS customer id
(integer) 1
127.0.0.1:6379> HEXISTS customer tid
(integer) 0
127.0.0.1:6379> HKEYS customer
1) "id"
2) "name"
3) "age"
127.0.0.1:6379> HVALS customer
1) "11"
2) "wgy"
3) "26"
127.0.0.1:6379> HINCRBY customer age 2
(integer) 28
127.0.0.1:6379> HINCRBY customer age 3
(integer) 31
127.0.0.1:6379> HSET customer score 91.5
(integer) 1
127.0.0.1:6379> HINCRBYFLOAT customer score 0.5
"92"
127.0.0.1:6379> HSETNX customer age 26
(integer) 0
127.0.0.1:6379> HSETNX customer email ab@163.com
(integer) 1
 

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 2
博文 65
码字总数 43479
×
double大宝
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: