# TTL

> Return a key's remaining time to live in seconds.

URL: https://docs.hotkv.com/commands/ttl/

```
TTL key
```

- Group: Keys
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`TTL` returns how many seconds are left before `key` expires, rounded to the
nearest second, so a `TTL` right after `EXPIRE key 100` reads `100`. Reading
the time to live is not an access to the key.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The key has a time to live | Integer: seconds left | Integer |
| The key exists without a time to live | Integer `-1` | Integer `-1` |
| The key does not exist | Integer `-2` | Integer `-2` |

## Examples

```
127.0.0.1:6379> SET token "x" EX 30
OK
127.0.0.1:6379> TTL token
(integer) 30
127.0.0.1:6379> SET plain "y"
OK
127.0.0.1:6379> TTL plain
(integer) -1
127.0.0.1:6379> TTL missing
(integer) -2
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[PTTL](https://docs.hotkv.com/commands/pttl/index.md), [NTTL](https://docs.hotkv.com/commands/nttl/index.md),
[EXPIRETIME](https://docs.hotkv.com/commands/expiretime/index.md), [EXPIRE](https://docs.hotkv.com/commands/expire/index.md)