redis到期设置时长expire用法
- get keys :查看缓存
- auth 密码:登录redis
- keys *:查看所有的缓存
- ttl keys:查看缓存时间
- expire key seconds:设置缓存时间
1,连接redis
在redis目录下找到src目录,然后在src目录下找到redis-cli连接上redis
![f76abf96fe8a41c6bbb52b03eed44b8a.png f76abf96fe8a41c6bbb52b03eed44b8a.png](https://picturecdn.ejianmedia.com/f76abf96fe8a41c6bbb52b03eed44b8a.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/7ef631135eda4430806c7f5eaa7a64ef/clipboard.png)
2,登录redis
如果redis有密码的话需要登录redis,提示noauth authentication required 说明需要密码登录
![b8db79b7ff81436589eaed362fcebc86.png b8db79b7ff81436589eaed362fcebc86.png](https://picturecdn.ejianmedia.com/b8db79b7ff81436589eaed362fcebc86.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/36fe6735446b47a6afd4aa8d562cb675/clipboard.png)
登录:auth 密码,登录成功后会返回ok
![a645fd5c8d434f20954a8ddb748e2028.png a645fd5c8d434f20954a8ddb748e2028.png](https://picturecdn.ejianmedia.com/a645fd5c8d434f20954a8ddb748e2028.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/c91904ab95774189a00175063a10591e/clipboard.png)
3,查询所有的缓存值:keys *
![abfec7e3629d46118b2241dabe4602c2.png abfec7e3629d46118b2241dabe4602c2.png](https://picturecdn.ejianmedia.com/abfec7e3629d46118b2241dabe4602c2.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/583d5840ddfe4d0e8250271f0dae4f28/clipboard.png)
4,查找具体某一个缓存值:get key(key就是上一步查出来的具体的缓存值)
![bd81a0d883004315a1a1ab66fea474f8.png bd81a0d883004315a1a1ab66fea474f8.png](https://picturecdn.ejianmedia.com/bd81a0d883004315a1a1ab66fea474f8.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/d24588c2bc6e4dcbb3aeb2f815d107e2/clipboard.png)
5,查看缓存到期时间:ttl key(第三步具体的key值)
![e2afe0540aff4d8382078072bb7f797e.png e2afe0540aff4d8382078072bb7f797e.png](https://picturecdn.ejianmedia.com/e2afe0540aff4d8382078072bb7f797e.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/3b886288e0e64d109948efb1d2bebc07/clipboard.png)
6,设置缓存到期时间 expire keys(第三步具体的key值) 时间(单位s),返回1说明设置成功
![a076d414f51d45239cbec532601d35c9.png a076d414f51d45239cbec532601d35c9.png](https://picturecdn.ejianmedia.com/a076d414f51d45239cbec532601d35c9.png)
![](C:/Users/wafer/AppData/Local/YNote/data/qq419ADA7807A936A0BADC84F6DBDBC1EA/f9f6d4d80d234db797a88bf3dad28bce/clipboard.png)
每次查询缓存到期时间,时间会一直减少,减少为-2说明已经过期
评论前必须登录!
注册