Redis - Keys Ttl 命令



Redis TTL 命令用于获取键的剩余过期时间(以秒为单位)。

返回值

以毫秒为单位的整数 TTL 值或负值。

  • 以毫秒为单位的 TTL 值。
  • -1,如果键没有过期超时时间。
  • -2,如果键不存在。

语法

以下是 Redis TTL 命令的基本语法。

redis 127.0.0.1:6379> TTL KEY_NAME 

示例

首先,在 Redis 中创建键并设置一些值。

redis 127.0.0.1:6379> SET tutorialname redis 
OK 

现在,设置键的过期时间,稍后检查剩余的过期时间。

redis 127.0.0.1:6379> EXPIRE tutorialname 60 
1) (integer) 1 
redis 127.0.0.1:6379> TTL tutorialname 
1) (integer) 59
redis_keys.htm
广告
© . All rights reserved.