查找键,参数支持正则
KEYS pattern
python3:0>keys *
1) "testkey"
2) "morekey"
3) "morekey2"
4) "morekey1"
python3:0>keys [^m]*
1) "testkey"
判断键是否存在,如果存在返回1,不存在返回0
EXISTS key [key …]
python3:0>exists 111
"0"
python3:0>exists morekey
"1"
查看键对应的value的类型
TYPE key
python3:0>type morekey
"string"
删除键及对应的值
DEL key [key …]
python3:0>del morekey2
"1"
设置过期时间,以秒为单位
创建时没有设置过期时间则一直存在,直到使用使用DEL移除
EXPIRE key seconds
查看有效时间,以秒为单位
TTL key
python3:0>expire morekey1 60
"1"
python3:0>ttl morekey1
"47"