Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Pttl Command

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 Version

= 2.6.0

Return Value

Returns -2 if key does not exist. Returns -1 if key exists but has no remaining time to live. Otherwise, returns the remaining time to live of the key in milliseconds.

**Note:** Before Redis 2.8, the command returned -1 when key does not exist or when key has no remaining time to live set.

Example



# Non-existent key



redis> FLUSHDB

OK



redis> PTTL key

(integer) -2





# key exists, but no remaining time set



redis> SET key value

OK



redis> PTTL key

(integer) -1





# key with remaining survival time



redis> PEXPIRE key 10086

(integer) 1



redis> PTTL key

(integer) 6179

Redis Key