1.keys *
遍历所有的key 只显示key 不显示value

keys[pattern]
遍历所有符合通配符的key
keys he* he开头
keys he[h-l]* 第三位为 h-l
keys he? he开头 限制长度为3
keys 命令一般不在生产环境使用 O(n)命令 实际环境有几百万的key Redis是单线程会阻塞其他命令
keys 该怎么用 scan命令 热备从节点 在从节点执行
2.dbsize
计算key的总数

sadd 添加set集合
3.exists key
检查一个key是否存在
4.del key1 key2 key3
删除多个key

set 实际上是一种 一个key对应多个value的集合
exists key 存在 integer 为 1 否则为0 keyvalue 为空返回nil
5.expire key seconds
key在seconds秒后过期
6.ttl key
查看key剩余的过期时间
7.persist key
去掉key的过期时间

为-2表示key已经不存在,已经过期 -1表示没有设置过期时间
8.type key
返回key的类型 string hash list set zset none

#
时间复杂度
keys O(n)
dbsize del exists expire type O(1)
网友评论