v0.7.0

daemon 套件

最後更新


本頁列出 core/daemon 的公開 API:生命週期、資料方法、傳輸型別與錯誤。

生命週期


  1. func New(dir string, apiKey ...string) (*Daemon, error)
  2. func (d *Daemon) Start() error
  3. func (d *Daemon) Stop() error
  4. func (d *Daemon) Close() error
  5. func (d *Daemon) Mode() Mode
  6. func (d *Daemon) Socket() string
  7. func (d *Daemon) Store() *store.Store
  8. type Mode int
  9. const (
  10. ModeServer Mode = iota
  11. ModeClient
  12. )

Client 模式下 Store() 為 nil。各模式的生命週期行為見 Socket Daemon。

資料


  1. func (d *Daemon) Get(ctx context.Context, db int, key string) (*Record, error)
  2. func (d *Daemon) Entries(ctx context.Context, db int, pattern string, option *ScanOption) ([]Record, error)
  3. func (d *Daemon) Set(ctx context.Context, db int, key string, content any, expireAt *int64) error
  4. func (d *Daemon) SetVector(ctx context.Context, db int, key string, content any, expireAt *int64) error
  5. func (d *Daemon) Del(ctx context.Context, db int, keys ...string) (int, error)
  6. func (d *Daemon) TTL(ctx context.Context, db int, key string) (int64, error)
  7. func (d *Daemon) Expire(ctx context.Context, db int, ttl int64, keys ...string) (int, error)
  8. func (d *Daemon) Keys(ctx context.Context, db int, pattern string, limit, page int) (*ListResult, error)
  9. func (d *Daemon) VSearch(ctx context.Context, db int, text, pattern string, limit int) ([]string, error)
  10. func (d *Daemon) HasEmbedder(ctx context.Context) (bool, error)

型別與錯誤


  1. type ScanOption struct {
  2. Contains string
  3. After int64
  4. Limit int
  5. }
  6. type Record struct {
  7. DB int `json:"db"`
  8. Key string `json:"key"`
  9. Type string `json:"type"`
  10. Content json.RawMessage `json:"content,omitempty"`
  11. CreatedAt int64 `json:"created_at,omitempty"`
  12. UpdatedAt *int64 `json:"updated_at,omitempty"`
  13. ExpireAt *int64 `json:"expire_at,omitempty"`
  14. }
  15. func (r *Record) Value() (string, error)
  16. type ListResult struct {
  17. DB int `json:"db"`
  18. Page int `json:"page"`
  19. Limit int `json:"limit"`
  20. Total int `json:"total"`
  21. Keys []string `json:"keys"`
  22. }
  23. var (
  24. ErrAlreadyRunning = errors.New("another daemon is serving this socket")
  25. ErrNotFound = errors.New("not found")
  26. ErrBadRequest = errors.New("bad request")
  27. ErrNoEmbedder = store.ErrNoEmbedder
  28. )

Record 與 ListResult 本身就是 wire 型別。對於 json/int/float/bool 且為合法 JSON 的值,Content 存放原始 JSON,其餘為 JSON 字串;Value() 在兩種情況下都回傳儲存的文字。

相關頁面


EN