# Daemon 資料方法

本頁列出 `Daemon` 的讀寫方法；不論 process 是 server 或 client，行為都相同。

## 資料方法

| 方法 | 結果 |
|---|---|
| `Get(ctx, db, key)` | `*Record`；不存在或已過期回 `ErrNotFound` |
| `Entries(ctx, db, pattern, *ScanOption)` | 在 server 端篩選後的 `[]Record` |
| `Set(ctx, db, key, content, expireAt)` | Upsert；`content` 為任何可 JSON 序列化的值 |
| `SetVector(ctx, db, key, content, expireAt)` | Upsert 並在背景產生 embedding；無 key 時回 `ErrNoEmbedder` |
| `Del(ctx, db, keys...)` | 刪除數量；零個鍵直接回 `0`，不發請求 |
| `TTL(ctx, db, key)` | 秒數，永久為 `-1`；不存在回 `ErrNotFound` |
| `Expire(ctx, db, ttl, keys...)` | 成功套用 TTL 的鍵數；零個鍵回 `0` |
| `Keys(ctx, db, pattern, limit, page)` | `*ListResult` |
| `VSearch(ctx, db, text, pattern, limit)` | 依相似度排序的鍵 |
| `HasEmbedder(ctx)` | Server 端 store 是否有 embedder |

`Set` 將 JSON 字串值存為去除引號的文字，其他 JSON 值則存為壓縮後的 JSON。`null` 或空內容會以 `ErrBadRequest` 拒絕。讀回時使用 `Record.Value()`，不要用 `string(record.Content)`，否則字串值會多出引號與跳脫字元。

## 相關頁面

- [Server 端篩選](/zh/socket-daemon-filtering)
- [daemon](/zh/api-reference-daemon)
- [錯誤](/zh/core-concepts-errors)
