keys * 显示所有key
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "name"
4) "set1"
5) "set2"
6) "sort1"
查找所有以s开头的key
用s* *表示任意字符
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "name"
4) "set1"
5) "set2"
6) "sort1"
127.0.0.1:6379> keys s*
1) "set3"
2) "set4"
3) "set1"
4) "set2"
5) "sort1"
查找所有s开头,后面紧跟任意一个(或几个)字符的key
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "name"
4) "set1"
5) "set2"
6) "sort1"
127.0.0.1:6379> keys set?
1) "set3"
2) "set4"
3) "set1"
4) "set2"
del 删除key
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "name"
4) "set1"
5) "set2"
6) "sort1"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "set1"
4) "set2"
5) "sort1"
exists 判断key是否存在 1表示存在 0表示不存在
127.0.0.1:6379> keys *
1) "set3"
2) "set4"
3) "set1"
4) "set2"
5) "sort1"
127.0.0.1:6379> exists set4
(integer) 1
127.0.0.1:6379> exists set5
(integer) 0
get 获取元素
127.0.0.1:6379> set name aro
OK
127.0.0.1:6379> get name
"aro"
rename 对key重命名
127.0.0.1:6379> rename name name123
OK
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> get name123
"aro"
expire 对key设置有效时间
127.0.0.1:6379> expire name123 120
(integer) 1
ttl 查看剩余时间
127.0.0.1:6379> expire name123 120
(integer) 1
127.0.0.1:6379> ttl name123
(integer) 91
127.0.0.1:6379> ttl name123
(integer) 86
type 显示类型
127.0.0.1:6379> type name123
string
127.0.0.1:6379> type sort1
zset
127.0.0.1:6379> type set1
set