Skip to main content

Description

Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset.

Method Signature

Parameters

key
string
required
The key to get the time to live for

Return Value

result
number
The time to live in seconds, or:
  • -2 if the key does not exist
  • -1 if the key exists but has no associated expire

Examples

Get TTL for a key with expiration

Key with no expiration

Non-existent key

Monitor TTL over time

See Also

  • expire - Set a key’s time to live
  • persist - Remove the expiration from a key