# TTL、EXPIRE、EXPIREAT 與 PERSIST

本頁說明 ToriiDB 讀取、設定與移除鍵過期時間的指令。

## 過期

```text
TTL <key>
EXPIRE <key> <seconds>
EXPIREAT <key> <timestamp>
PERSIST <key>
```

| 指令 | 回應規則 |
|---|---|
| `TTL` | 無過期為 `(integer) -1`；不存在或已過期為 `(nil)` |
| `EXPIRE` | `<= 0` 或非整數為 `error: seconds must be a positive integer`；不存在為 `(nil)` |
| `EXPIREAT` | `error: timestamp must be a valid integer`；不存在為 `(nil)` |
| `PERSIST` | 不存在為 `(nil)` |

## 相關頁面

- [過期](/zh/core-concepts-expiration)
- [指令摘要](/zh/cli-reference)
- [SET、DEL、INCR](/zh/cli-reference-write)
