慕课网-一站式学习Redis从入门到高可用分布式实践-第2章-API的理解和使用-通用命令

通用命令

1.通用命令

a)keys

keys 命令一般不在生产环境使用,不然会麻烦

keys*怎么用

  A--热备从节点

       B--scan

#遍历所有 key
keys [pattern]

#演示
set hello world
set php good
set java best
keys *
dbsize

#演示
mset hello world hehe haha php good phe his
keys he*
keys he[h-l]*
keys ph?           

b)dbsize

#计算key的总数
#dbsize

#演示
mset k1 v1 k2 v2 k3 v3 k4 v4
dbsize
sadd myset a b c d e

c)exists key

#检查key是否存在,存在返回1,不存在返回0
#exists key

#演示
set a b
exists a
del a
exists a

d)del key [key ...]

#删除指定 key-value,成功删除返回1,否则返回 0
#del key

#演示
set a b
get a
del a
get a

e)expire key seconds

#key 在 seconds 秒后过期
#expire key seconds

#查看key剩余的过期时间
#ttl key

#去掉key的过期时间
#persist key

#演示,-2代表key已经不存在了
set hello world
expire hello 20
ttl hello
get hello
ttl hello
ttl hello 

#演示, -1 代表key存在,并且没有过期时间
set hello world
expire hello 20
ttl hello
persist hello
ttl hello
get hello

f)type key

#返回key的类型
#type key

#演示
#返回类型包括,string、hash、list、set、zset、none
set a b
type a
sadd myset 1 2 3
type myset

2.数据结构和内部编码

3.单线程架构

 

时间复杂度

命令 时间复杂度
keys O(n)
dbsize O(1)
del O(1)
exists O(1)
expire O(1)
type O(1)

 

posted on 2019-11-07 12:18  herisson_pan  阅读(12)  评论(0)    收藏  举报

导航