What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

PTTL

Returns the expiration time in milliseconds of a key.

Usage
PTTL key
Complexity
O(1)
Since
2.6.0
ACL Categories
@fast, @keyspace, @read
Command flags
READONLY, FAST

Like TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.

The command returns the following values in case of errors:

  • The command returns -2 if the key does not exist.
  • The command returns -1 if the key exists but has no associated expire.

Examples

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> EXPIRE mykey 1
(integer) 1
127.0.0.1:6379> PTTL mykey
(integer) 989

Replies

RESP2

One of the following:

RESP3

One of the following:

History

  • 2.8.0: Added the -2 reply.