kvstore

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KV_STORE = "kv-store"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteCallback

type DeleteCallback func(context.Context, string) error

type GetCallback

type GetCallback func(context.Context, string, ...GetOpt) ([]*Record, error)

type GetOpt

type GetOpt interface{}

GetOpts are the additional options passed during the get opertation

type KVStore

type KVStore interface {
	component.Component
	// Init initializes the store with the given options
	Init(opts ...Option) error
	// Put the value for the key
	Put(ctx context.Context, record *Record, opts ...SetOpt) (*Record, error)
	// Get the value for the key
	Get(ctx context.Context, key string, opts ...GetOpt) ([]*Record, error)
	// Delete the key from the store
	Delete(ctx context.Context, key string) error
	// Txn handles transactions
	Txn(ctx context.Context, handler TxnHandler) error
	// Subscribe to the changes made to the given key
	Subscribe(ctx context.Context, key string, handler SubscribeHandler, opts ...SubscribeOpt) error
	// Unsubscribe from a subscription
	Unsubscribe(ctx context.Context, key string) error
	// String returns the name of the store implementation
	String() string
}

KVStore is a key-value data storage interface

type Option

type Option interface{}

Option for initialization of the store

type PutCallback

type PutCallback func(context.Context, *Record, ...SetOpt) (*Record, error)

type Record

type Record struct {
	// Key to store the record
	Key string `json:"key"`
	// Value for the key set in the store
	Value []byte `json:"value"`
	// Expiry is the time to expire a record
	Expiry time.Duration `json:"expiry,omitempty"`
	// Metadata is the metadata of the record
	Metadata map[string]interface{} `json:"metadata"`
}

Record set in the store for a specific key

type SetOpt

type SetOpt interface{}

SetOpts are the additional options passed during the set operation

type SubscribeCallback

type SubscribeCallback func(context.Context, string, SubscribeHandler) error

type SubscribeHandler

type SubscribeHandler interface {
	// Handle the subscription for the given key
	Handle(ctx context.Context, key string, args ...interface{}) error
}

SubscribeHandler for the subscribe action

type SubscribeOpt

type SubscribeOpt interface{}

SubscribeOpt are the additional options passed during the subscribe operation

type Trace

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

func NewTrace

func NewTrace(s KVStore) *Trace

func (*Trace) Delete

func (t *Trace) Delete(ctx context.Context, key string, delete DeleteCallback) error

func (*Trace) Get

func (t *Trace) Get(ctx context.Context, key string, get GetCallback, opts ...GetOpt) ([]*Record, error)

func (*Trace) HandlerHandle

func (t *Trace) HandlerHandle(
	ctx context.Context,
	key string,
	handler SubscribeHandler,
	args ...interface{},
) error

func (*Trace) Put

func (t *Trace) Put(ctx context.Context, record *Record, put PutCallback, opts ...SetOpt) (*Record, error)

func (*Trace) Subscribe

func (t *Trace) Subscribe(ctx context.Context, key string, handler SubscribeHandler, subscribe SubscribeCallback) error

func (*Trace) Txn

func (t *Trace) Txn(ctx context.Context, handler TxnHandler, txn TxnCallback) error

type TxnCallback

type TxnCallback func(context.Context, TxnHandler) error

type TxnHandler

type TxnHandler interface {
	// Handle the transaction
	Handle(ctx context.Context, store KVStore) error
}

TxnHandler is the interface for handling transactions

type Wrapper

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

func NewWrapper

func NewWrapper(s KVStore) *Wrapper

NewWrapper returns a new KVStore wrapper

func (*Wrapper) Delete

func (w *Wrapper) Delete(
	ctx context.Context,
	key string,
	delete DeleteCallback,
) error

func (*Wrapper) Get

func (w *Wrapper) Get(
	ctx context.Context,
	key string,
	get GetCallback,
	opts ...GetOpt,
) ([]*Record, error)

func (*Wrapper) HandlerHandle

func (w *Wrapper) HandlerHandle(
	ctx context.Context,
	key string,
	handler SubscribeHandler,
	args ...interface{},
) error

func (*Wrapper) Put

func (w *Wrapper) Put(
	ctx context.Context,
	record *Record,
	put PutCallback,
	opts ...SetOpt,
) (*Record, error)

func (*Wrapper) Subscribe

func (w *Wrapper) Subscribe(
	ctx context.Context,
	key string,
	handler SubscribeHandler,
	subscribe SubscribeCallback,
) error

func (*Wrapper) Txn

func (w *Wrapper) Txn(
	ctx context.Context,
	handler TxnHandler,
	txn TxnCallback,
) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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