Documentation ¶
Overview ¶
Package mem defines Store, an in-memory key-value store that implements the Store interface defined in "github.com/gokv/store".
Index ¶
- Variables
- type Store
- func (s *Store) Add(ctx context.Context, v json.Marshaler) (string, error)
- func (s *Store) Cleanup(ctx context.Context)
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, k string) (bool, error)
- func (s *Store) Get(ctx context.Context, k string, v json.Unmarshaler) (bool, error)
- func (s *Store) GetAll(ctx context.Context, c store.Collection) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Set(ctx context.Context, k string, v json.Marshaler) error
- func (s *Store) SetWithDeadline(ctx context.Context, k string, v json.Marshaler, deadline time.Time) error
- func (s *Store) SetWithTimeout(ctx context.Context, k string, v json.Marshaler, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ErrKeyExists = errors.New("the key already exists")
ErrKeyExists is returned when the Add method generates a non-unique ID.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements an in-memory key-value store. It is implemented as a Go map and protected by a mutex. The zero value is not ready to use: initialise with New.
Store is safe for concurrent use.
func (*Store) Add ¶
Add persists a new object and returns its unique UUIDv4 key. Err is non-nil in case of failure.
func (*Store) Delete ¶
Delete removes the corresponding entry if present. Returns a non-nil error if the key is not known or if the context is Done.
func (*Store) Get ¶
Get returns the value corresponding the key, and a nil error. If no match is found, returns (false, nil).
func (*Store) Set ¶
Set assigns the given value to the given key, possibly overwriting. The returned error is not nil if the context is Done.
func (*Store) SetWithDeadline ¶
func (s *Store) SetWithDeadline(ctx context.Context, k string, v json.Marshaler, deadline time.Time) error
SetWithDeadline assigns the given value to the given key, possibly overwriting. The assigned key will clear after deadline.
func (*Store) SetWithTimeout ¶
func (s *Store) SetWithTimeout(ctx context.Context, k string, v json.Marshaler, timeout time.Duration) error
SetWithTimeout assigns the given value to the given key, possibly overwriting. The assigned key will clear after timeout. The lifespan starts when this function is called.