Redis中常用的五种数据类型:
1、字符串(String)
2、字符串列表(List)
3、有序字符串集合(Sorted list)
4、哈希(Hash)
5、字符串集合(Set)
一、存储哈希(Hash)常用的命令
a.赋值hset/hmset
b,取值hget/hmget/hgetall
c.删除hdel
d.增加数字hincrby
e.自学命令hexists/hlen/hkeys/hvals
127.0.0.1:6379> hset myhash username hwm
(integer) 1
127.0.0.1:6379> hset muhash age 18
(integer) 1
127.0.0.1:6379> hmset muhash2 username zwy age 21
OK
127.0.0.1:6379> hget myhash username
"hwm"
127.0.0.1:6379> hmget myhash username age
1) "hwm"
2) "12"
127.0.0.1:6379> hgetall myhash
1) "username"
2) "hwm"
3) "age"
4) "12"
127.0.0.1:6379> hdel muhash2 username age
(integer) 2
127.0.0.1:6379> hgetall muhash2
(empty array)
127.0.0.1:6379> hset myhash2 username hwm
(integer) 1
127.0.0.1:6379> del myhash2
(integer) 1
127.0.0.1:6379> hget myhash2 username
(nil)
127.0.0.1:6379> hget myhash age
"12"
127.0.0.1:6379> hincrby myhash age 5
(integer) 17
127.0.0.1:6379> hget myhash age
"17"
127.0.0.1:6379> hgetall myhash
1) "username"
2) "hwm"
3) "age"
4) "17"
127.0.0.1:6379> hexists myhash age
(integer) 1
127.0.0.1:6379> hlen myhash
(integer) 2
127.0.0.1:6379> hkeys myhash
1) "username"
2) "age"
127.0.0.1:6379> hvals myhash
1) "hwm"
2) "17"
127.0.0.1:6379>