Easy Tutorial
❮ Strings Mset Connection Auth ❯

Redis Pttl Command

Redis Key

The Redis Pttl command returns the remaining time to live of a key in milliseconds.

Syntax

The basic syntax of the redis Pttl command is as follows:

redis 127.0.0.1:6379> PTTL KEY_NAME

Available Versions

= 2.6.0

Return Value

When the key does not exist, it returns -2. When the key exists but has no remaining生存 time set, it returns -1. Otherwise, it returns the remaining生存 time of the key in milliseconds.

Note: Before Redis 2.8, the command returned -1 for both non-existent keys and keys with no remaining生存 time.

Examples

# Non-existent key

redis> FLUSHDB
OK

redis> PTTL key
(integer) -2


# Key exists but has no remaining生存 time

redis> SET key value
OK

redis> PTTL key
(integer) -1


# Key with remaining生存 time

redis> PEXPIRE key 10086
(integer) 1

redis> PTTL key
(integer) 6179

Redis Key

❮ Strings Mset Connection Auth ❯