1.设置
127.0.0.1:6379> set b 2
OK
2.获取
127.0.0.1:6379> get b
"2"
3.设置多个,获取多个
127.0.0.1:6379> mset a 1 b 2 c 3
OK
127.0.0.1:6379> mget a b c
1) "1"
2) "2"
3) "3"
4.判断是否存在与删除
127.0.0.1:6379> exists b
(integer) 1
127.0.0.1:6379> del b
(integer) 1
127.0.0.1:6379> exists b
(integer) 0
127.0.0.1:6379> get b
(nil)
5.修改
127.0.0.1:6379> set b 3
OK
127.0.0.1:6379> get b
"3"
6.设置生存时间
127.0.0.1:6379> expire b 3
(integer) 1
7.获取过期时间
127.0.0.1:6379> ttl b
(integer) 2
127.0.0.1:6379> ttl b
(integer) 1
127.0.0.1:6379> ttl b
(integer) -2
127.0.0.1:6379> get b
(nil)
8.持久化(ttl -1表示key没有设置超时时间)
127.0.0.1:6379> set b 3
OK
127.0.0.1:6379> ttl b
(integer) -1
127.0.0.1:6379> expire b 30
(integer) 1
127.0.0.1:6379> persist b
(integer) 1
127.0.0.1:6379> ttl b
(integer) -1
127.0.0.1:6379> set b 2
OK
2.获取
127.0.0.1:6379> get b
"2"
3.设置多个,获取多个
127.0.0.1:6379> mset a 1 b 2 c 3
OK
127.0.0.1:6379> mget a b c
1) "1"
2) "2"
3) "3"
4.判断是否存在与删除
127.0.0.1:6379> exists b
(integer) 1
127.0.0.1:6379> del b
(integer) 1
127.0.0.1:6379> exists b
(integer) 0
127.0.0.1:6379> get b
(nil)
5.修改
127.0.0.1:6379> set b 3
OK
127.0.0.1:6379> get b
"3"
6.设置生存时间
127.0.0.1:6379> expire b 3
(integer) 1
7.获取过期时间
127.0.0.1:6379> ttl b
(integer) 2
127.0.0.1:6379> ttl b
(integer) 1
127.0.0.1:6379> ttl b
(integer) -2
127.0.0.1:6379> get b
(nil)
8.持久化(ttl -1表示key没有设置超时时间)
127.0.0.1:6379> set b 3
OK
127.0.0.1:6379> ttl b
(integer) -1
127.0.0.1:6379> expire b 30
(integer) 1
127.0.0.1:6379> persist b
(integer) 1
127.0.0.1:6379> ttl b
(integer) -1