数据结构:
Hash,与Map的数据结构相比较,K,V模式不变,V是一个键值对。
Hash常用使用命令:
HSET / HGET:创建 / 获取一个键值对
115.159.67.200:6379[1]> HSET user id 1001
(integer) 1
115.159.67.200:6379[1]> HGET user id
"1001"
HMSET / HMGET:一次性为key创建 / 获取多个属性和值
115.159.67.200:6379[1]> HMSET user gender man age 20
OK
115.159.67.200:6379[1]> HMGET user
115.159.67.200:6379[1]> HMGET user id gender age
1) "1001"
2) "man"
3) "20"
HGETALL:获取key的所有属性和值
115.159.67.200:6379[1]> HGETALL user
1) "id"
2) "1001"
3) "gender"
4) "man"
5) "age"
6) "20"
HDEL:删除key的某个属性
115.159.67.200:6379[1]> HDEL user gender
(integer) 1
115.159.67.200:6379[1]> HGETALL user
1) "id"
2) "1001"
3) "age"
4) "20"
HLEN:获取key的属性数量
115.159.67.200:6379[1]> HLEN user
(integer) 2
HEXISTS:查询key中是否存在某个属性,是返回1,否则返回0
115.159.67.200:6379[1]> HEXISTS user id
(integer) 1
115.159.67.200:6379[1]> HEXISTS user name
(integer) 0
HKEYS / HVALS:查询
115.159.67.200:6379[1]> HKEYS user
1) "id"
2) "age"
115.159.67.200:6379[1]> HVALS user
1) "1001"
2) "20"
HINCRBY / HINCRBYFLOAT :对数值型的属性值进行增加指定值操作
115.159.67.200:6379[1]> HINCRBY user age 2
(integer) 22
115.159.67.200:6379[1]> HINCRBY user age 2
(integer) 24
115.159.67.200:6379[1]> HSET user score 99.5
(integer) 1
115.159.67.200:6379[1]> HINCRBYFLOAT user score 0.5
"100"
HSETNX:set is not exsist创建还未存在的属性,若属性已存在则创建失败
115.159.67.200:6379[1]> HSETNX user id 111
(integer) 0
115.159.67.200:6379[1]> HSETNX user name zs
(integer) 1
115.159.67.200:6379[1]> HKEYS user
1) "id"
2) "age"
3) "score"
4) "name"