# Expiration

This page explains how ToriiDB keys get a TTL and the points at which expired keys are removed.

## Expiration

| Operation | Result |
|---|---|
| `TTL(key)` | remaining seconds; `-1` without expiry; `-2` when missing or expired |
| `Expire(key, seconds)` | `ExpireAt = now + seconds` |
| `ExpireAt(key, ts)` | absolute timestamp |
| `Persist(key)` | removes expiry |

Expired keys are enforced at several points:

- `Get` treats an expired entry as missing and deletes it from memory.
- `Keys`, `Find`, `Query`, and `VSearch` skip expired entries.
- A timer removes expired entries from every loaded database once per minute.
- Compaction does not write expired entries to the new snapshot.

## Related Pages

- [TTL Commands](/cli-reference-expiration)
- [Compaction and GC](/persistence-compaction)
- [Data Methods](/socket-daemon-methods)
