redis api的使用和理解

通用命令

  • 字符串类型
  • 哈希类型
  • 列表类型
  • 集合类型
  • 有序集合类型

通用命令:
通用命令
单线程架构
数据结构和内部编码
通用命令
keys 遍历所有的key
dbsize exisits key del key expire key seconds 设置过期 时间 type key 数据类型
api:keys *
遍历所有key

set hello world 
set php good 
set java best  
keys * 
java 
php 
hello  

1: keys

mset hello world heh haha php good phe his ok 
keys he[h-l]* 
"hehe"
"hello"
 keys ph? 

keys 一般不在生产环境中使用 执行效率比较慢 会堵塞其它线程
keys 热备到从节点
scan

2:dbsize

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

3:exists

set a b 
exists a 
del a 
exist a 

4:del

del key #删除指定的key-value 
set a b 
get a 
del a 
get a 

**5:expire ttl persist **

expire key seconds #key 在seconds秒后过期 
ttl key  #查看key剩余的过期时间 
persist key #去掉key的过期时间
set hello world 
>>ok 
expire hello 20 
>>1 
ttl hello 
>>16 
get hello 
>>world 
ttl hello 
>>-2 
>set hello world 
ok
>expire hello 20 
1
>ttl hello 
16
>persist hello 
1 
ttl hello 
-1 

6:type

  • string
  • hash
  • list
  • set
  • zset
  • none
>set a b
ok
>type a  
string
>sadd myset 1 2 3 
3 
type myset 
set    

*时间复杂度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值