Redis TTL 命令

更新时间: 2019-07-07 15:54

Redis TTL 命令以秒为单位返回 key 的剩余过期时间。

语法

redis 127.0.0.1:6379> TTL KEY_NAME

返回值

  • 当 key 不存在时,返回 -2 。

  • 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以秒为单位,返回 key 的剩余生存时间。

实例

实例1: 当 key 存在,但没有设置过期时间

127.0.0.1:6379> get domain
"www.codercto.com"
127.0.0.1:6379> ttl domain
(integer) -1

实例2: 当 key 不存在

127.0.0.1:6379> exists domain2
(integer) 0
127.0.0.1:6379> ttl domain2
(integer) -2

实例3: 当 key 存在且设置了过期时间

127.0.0.1:6379> exists domain
(integer) 1
127.0.0.1:6379> EXPIRE domain 60
(integer) 1
127.0.0.1:6379> ttl domain
(integer) 57

查看更多 Redis key 命令

An Introduction to Genetic Algorithms

An Introduction to Genetic Algorithms

Melanie Mitchell / MIT Press / 1998-2-6 / USD 45.00

Genetic algorithms have been used in science and engineering as adaptive algorithms for solving practical problems and as computational models of natural evolutionary systems. This brief, accessible i......一起来看看 《An Introduction to Genetic Algorithms》 这本书的介绍吧!

Base64 编码/解码

Base64 编码/解码

Base64 编码/解码

URL 编码/解码

URL 编码/解码

URL 编码/解码

UNIX 时间戳转换

UNIX 时间戳转换

UNIX 时间戳转换