v0.7.0

store 套件

最後更新


本頁列出 core/store 中開啟 store、寫入值,以及讀取與掃描鍵的函式。

生命週期與 Session


  1. func New(dir string, apiKey ...string) (*Store, error)
  2. func (s *Store) Session() *Session
  3. func (s *Store) Close() error

Store 與 Session 都內嵌未導出的 core,因此下列方法兩者皆可用。
  1. func (c *core) Current() int
  2. func (c *core) Select(index int) error
  3. func (c *core) HasEmbedder() bool
  4. func (c *core) Exec(input string) string
  5. func (c *core) DB() *db

DB 回傳目前選定的資料庫,首次使用時從磁碟重播;其型別未導出,在套件外只能當作不透明的 handle。

寫入


  1. type SetFlag int
  2. const (
  3. SetDefault SetFlag = iota
  4. SetNX
  5. SetXX
  6. )
  7. func (c *core) Set(key, value string, flag SetFlag, expireAt *int64) error
  8. func (c *core) SetVector(ctx context.Context, key, value string, flag SetFlag, expireAt *int64) error
  9. func (c *core) SetField(key string, subKeys []string, value string, flag SetFlag, expireAt *int64) error
  10. func (c *core) Incr(key string, delta float64) (float64, error)
  11. func (c *core) IncrField(key string, subKeys []string, delta float64) (float64, error)
  12. func (c *core) Del(keys ...string) int
  13. func (c *core) DelField(key string, subKeys []string) error

讀取與掃描


  1. func (c *core) Get(key string) (*Entry, bool)
  2. func (c *core) GetField(key string, subKeys []string) (string, bool)
  3. func (c *core) Exist(key string) string
  4. func (c *core) ExistField(key string, subKeys []string) string
  5. func (c *core) Type(key string) string
  6. func (c *core) TypeField(key string, subKeys []string) string
  7. func (c *core) Keys(pattern string) []string
  8. func (c *core) Find(op filter.Operator, value string, limit int) []string
  9. func (c *core) Query(f filter.Filter, limit int) []string

Exist、ExistField、Type、TypeField 回傳 REPL 文字形式。Query 回傳 key: value 字串。limit <= 0 代表不限制。

相關頁面


EN