Redis can be told that a key should only exist for a certain length of time. This is accomplished with the EXPIRE and TTL commands.

    SET resource:lock "Redis Demo"
EXPIRE resource:lock 120
This causes the key resource:lock to be deleted in 120 seconds. You can test how long a key will exist with the TTL command. It returns the number of seconds until it will be deleted. TTL resource:lock => 113
// after 113s
TTL resource:lock => -2
The -2 for the TTL of the key means that the key does not exist (anymore). A -1 for the TTL of the key means that it will never expire. Note that if you SET a key, its TTL will be reset. SET resource:lock "Redis Demo 1"
EXPIRE resource:lock 120
TTL resource:lock => 119
SET resource:lock "Redis Demo 2"
TTL resource:lock => -1

EXPIRE: 设置一个key的存活时间

TTL:      查询一个Key的存活时间

最新文章

  1. In-Memory:内存数据库
  2. less入门
  3. 使用antd UI组件有感
  4. Linux C 字符串输出函数 puts()、fputs()、printf() 详解
  5. JS 根据特定URL获取ID数组
  6. ASP.NET获取IP的6种方法 ( 转)
  7. Java MD5加密工具类
  8. win7开启硬盘AHCI
  9. Android,iOS,浏览器打开手机QQ与指定用户聊天界面
  10. SQL Server2008知识点总结
  11. iOS注册远程推送消息证书后提示此证书签发者无效的解决办法
  12. [ubuntu]apt-get update突然出现arm package找不到
  13. Django model 字段类型及选项解析---转载
  14. iptables 配置说明
  15. 死锁排查的小窍门 --使用jdk自带管理工具jstack
  16. 07 zabbix之map拓扑标签中macro应用
  17. 【转】Ubuntu FireFox无法播放网页视频音乐的解决办法
  18. php 带省略号的分页
  19. Linux fdisk普通分区扩容
  20. RAPID程序设计

热门文章

  1. VCL源码修改立即生效
  2. poj3539 Elevator——同余类bfs
  3. js addeventlistener 刮刮贴
  4. 湖南集训day5
  5. [Swift通天遁地]八、媒体与动画-(1)实现音频的播放和停止
  6. $ST表刷题记录$
  7. JavaScript--二维数组
  8. Java系列学习(六)-数组
  9. fcc 响应式框架Bootstrap 练习3
  10. Microsoft SQL Server学习(二)--数据库的语法