gostore

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 10 Imported by: 0

README

codecov Test status Go Report Card GoDev GitHub release

gostore

gostore is a simple key-value store written in Go. but it provides a layer of fast access read interface.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned when the key supplied to a Get or Delete
	// method does not exist in the database.
	ErrKeyNotFound = errors.New("key not found")

	// ErrKeyExpired is returned when the key supplied to a Get or Delete
	ErrKeyExpired = errors.New("key expired")

	// ErrBadValue is returned when the value supplied to the Put method
	// is nil.
	ErrBadValue = errors.New("bad value")
)

Functions

This section is empty.

Types

type Option

type Option func(*option) error

Option the tracer provider option

func WithMaxCacheSize

func WithMaxCacheSize(maxCacheSize int) Option

WithMaxCacheSize sets the maximum number of items in the LRU cache.

func WithNumRetries

func WithNumRetries(n uint8) Option

WithNumRetries defines service name

func WithReadOnly

func WithReadOnly() Option

WithReadOnly set the store to read-only mode

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is KVStore implementation based bolt DB

func Open

func Open(DbPath string, opts ...Option) (*Store, error)

Open opens a store with the given config

func (*Store) Close

func (s *Store) Close() error

Close closes the store

func (*Store) Delete

func (s *Store) Delete(namespace string, key []byte) error

Delete deletes a record by key

func (*Store) DeleteNamespace added in v1.1.0

func (s *Store) DeleteNamespace(namespace string) error

DeleteNamespace deletes a namespace

func (*Store) Get

func (s *Store) Get(namespace, key []byte) ([]byte, error)

Get fetches a value by key

func (*Store) Load

func (s *Store) Load(key string, obj any) error

Load read value by key

func (*Store) Memoize

func (s *Store) Memoize(key string, obj any, f func() (any, error)) error

Memoize memoize a function

func (*Store) MemoizeWithTTL added in v1.1.0

func (s *Store) MemoizeWithTTL(key string, obj any, f func() (any, error), ttl int64) error

func (*Store) Put

func (s *Store) Put(namespace string, key, value []byte) (err error)

Put inserts a <key, value> record

func (*Store) PutWithTTL added in v1.1.0

func (s *Store) PutWithTTL(namespace, key, value []byte, ttl int64) (err error)

PutWithTTL inserts a <key, value> record with TTL

func (*Store) Remove

func (s *Store) Remove(key string) error

Remove delete a record by key

func (*Store) Update

func (s *Store) Update(key string, value any) error

Update set value by key, value must be gob-encodable

func (*Store) UpdateWithTTL added in v1.1.0

func (s *Store) UpdateWithTTL(key string, value any, ttl int64) error

UpdateWithTTL set value by key with TTL, value must be gob-encodable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL