Redis命令整合(二)Hash型

hash类型主要用来存储对象,比如说存储一个汽车属性的值

1.连续赋值

hmset  [keyName] [field1] [value1]  [field2] [value2] ...
eg:
hmset car color "black" name "BMW" price 20000

2.连续获取值

eg:
hmget  car color name price

3.获取对象所有值

hgetall  [keyName]
eg:
hgetall car

4.判断是否含有某属性

eg:
hexists  car model

不存在则返回0,存在则返回1

 

5.如果不存在则赋值

hsetnx   car  model  C5000

不存在则给car加一个model属性,nx想到与 not exists

 

6.删除字段

hdel car model

 

7.只获取键名

hkeys    car

 

8.只获取值

hvals    car

 

posted @ 2023-12-11 16:56  RookieCoderAdu  阅读(8)  评论(0)    收藏  举报