mem: github.com/gokv/mem Index | Files

package mem

import "github.com/gokv/mem"

Package mem defines Store, an in-memory key-value store that implements the Store interface defined in "github.com/gokv/store".

Index

Package Files

cleanup.go doc.go store.go

Variables

var ErrKeyExists = errors.New("the key already exists")

ErrKeyExists is returned when the Add method generates a non-unique ID.

type Store Uses

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 New Uses

func New() *Store

New initialises the map underlying Store.

func (*Store) Add Uses

func (s *Store) Add(ctx context.Context, v json.Marshaler) (string, error)

Add persists a new object and returns its unique UUIDv4 key. Err is non-nil in case of failure.

func (*Store) Cleanup Uses

func (s *Store) Cleanup(ctx context.Context)

func (*Store) Close Uses

func (s *Store) Close() error

Close releases the resources associated with the Store.

func (*Store) Delete Uses

func (s *Store) Delete(ctx context.Context, k string) (bool, error)

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 Uses

func (s *Store) Get(ctx context.Context, k string, v json.Unmarshaler) (bool, error)

Get returns the value corresponding the key, and a nil error. If no match is found, returns (false, nil).

func (*Store) GetAll Uses

func (s *Store) GetAll(ctx context.Context, k string, c store.Collection) error

GetAll returns all values. Error is non-nil if the context is Done.

func (*Store) Ping Uses

func (s *Store) Ping(ctx context.Context) error

Ping always returns nil if the context is not Done.

func (*Store) Set Uses

func (s *Store) Set(ctx context.Context, k string, v json.Marshaler) error

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 Uses

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 Uses

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.

Package mem imports 7 packages (graph). Updated 2019-01-14. Refresh now. Tools for package owners.