v0.7.0

daemon Package

Last updated


This page lists the exported API of core/daemon: lifecycle, data methods, wire types, and errors.

Lifecycle


  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. )

Store() is nil in client mode. Lifecycle behavior per mode is in Socket Daemon.

Data


  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)

Types and Errors


  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 and ListResult are the wire types themselves. Content holds raw JSON for json/int/float/bool values that are valid JSON, and a JSON string otherwise; Value() returns the stored text either way.

中文