github.com/annwntech/go-micro/v2@v2.9.5/store/store.go (about)

     1  // Package store is an interface for distributed data storage.
     2  // The design document is located at https://github.com/micro/development/blob/master/design/store.md
     3  package store
     4  
     5  import (
     6  	"errors"
     7  	"time"
     8  )
     9  
    10  var (
    11  	// ErrNotFound is returned when a key doesn't exist
    12  	ErrNotFound = errors.New("not found")
    13  	// DefaultStore is the memory store.
    14  	DefaultStore Store = new(noopStore)
    15  )
    16  
    17  // Store is a data storage interface
    18  type Store interface {
    19  	// Init initialises the store. It must perform any required setup on the backing storage implementation and check that it is ready for use, returning any errors.
    20  	Init(...Option) error
    21  	// Options allows you to view the current options.
    22  	Options() Options
    23  	// Read takes a single key name and optional ReadOptions. It returns matching []*Record or an error.
    24  	Read(key string, opts ...ReadOption) ([]*Record, error)
    25  	// Write() writes a record to the store, and returns an error if the record was not written.
    26  	Write(r *Record, opts ...WriteOption) error
    27  	// Delete removes the record with the corresponding key from the store.
    28  	Delete(key string, opts ...DeleteOption) error
    29  	// List returns any keys that match, or an empty list with no error if none matched.
    30  	List(opts ...ListOption) ([]string, error)
    31  	// Close the store
    32  	Close() error
    33  	// String returns the name of the implementation.
    34  	String() string
    35  }
    36  
    37  // Record is an item stored or retrieved from a Store
    38  type Record struct {
    39  	// The key to store the record
    40  	Key string `json:"key"`
    41  	// The value within the record
    42  	Value []byte `json:"value"`
    43  	// Any associated metadata for indexing
    44  	Metadata map[string]interface{} `json:"metadata"`
    45  	// Time to expire a record: TODO: change to timestamp
    46  	Expiry time.Duration `json:"expiry,omitempty"`
    47  }