现在的位置: 首页 > 综合 > 正文

EXPIRE

2018年04月29日 ⁄ 综合 ⁄ 共 395字 ⁄ 字号 评论关闭

        EXPIRE命令的使用方法为EXPIRE key seconds.其中seconds参数表示键的生存时间,单位是秒。如要想让session:29e3d键在15分钟后被删除:

redis>SET session:29e3d uid1314
OK
redis>EXPIRE session:29e3d 900
(integer) 1

         EXPIRE命令返回1表示设置成功,返回0则表示键不存在或设置失败。
         如果想知道一个键还有多久的时间会被删除,可以使用TTL命令。返回值是键的剩余时间(单位是秒):

redis>SET foo bar
OK
redis>EXPIRE foo 20
(integer) 1
redis>TTL foo
(integer) 15
redis>TTL foo
(integer) 7
redis> TTL foo
(integer) -1

          当键不存在时TTL命令会返回​1。

抱歉!评论已关闭.