Arguments
str
required
The key
Response
The number of seconds until this expires, negative if the key does not exist or does not have an expiration set.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
# Get the TTL of a key
redis.set("my-key", "value")
assert redis.ttl("my-key") == -1
redis.expire("my-key", 10)
assert redis.ttl("my-key") > 0
# Non existent key
assert redis.ttl("non-existent-key") == -2
Return the expiration in seconds of a key.
# Get the TTL of a key
redis.set("my-key", "value")
assert redis.ttl("my-key") == -1
redis.expire("my-key", 10)
assert redis.ttl("my-key") > 0
# Non existent key
assert redis.ttl("non-existent-key") == -2
Was this page helpful?