> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# TTL

> Return the expiration in seconds of a key.

## Arguments

<ParamField body="key" type="str" required>
  The key
</ParamField>

## Response

<ResponseField type="int" required>
  The number of seconds until this expires, negative if the key does not exist or does not have an expiration set.
</ResponseField>

<RequestExample>
  ```py Example theme={"system"}
  # 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
  ```
</RequestExample>


## Related topics

- [TTL](/docs/redis/sdks/ts/commands/generic/ttl.md)
- [Redis® API Compatibility: supported commands, modules, and protocols](/docs/redis/overall/compatibility.md)
- [Memory, Chat History, RAG, Rate Limiting & Sandboxes for the Vercel Eve Agent Framework](/docs/redis/sdks/agentkit/eve.md)
- [Agent Memory with Redis Search](/docs/redis/tutorials/agent_memory.md)
- [Vercel AI SDK Memory, RAG & Chat History with Redis](/docs/redis/sdks/agentkit/ai-sdk.md)
