kv

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Prefix = "kv:"
)

Variables

This section is empty.

Functions

func KVKey

func KVKey(key string) string

Types

type IKV

type IKV interface {
	GetUsage(ctx context.Context) (*Usage, error)
	GetAll(ctx context.Context) ([]*protos.KVObject, error)
	Get(ctx context.Context, key string) (*protos.KVObject, error)
	Create(ctx context.Context, kvs []*protos.KVObject, overwrite bool) error
	Update(ctx context.Context, kv *protos.KVObject) (*protos.KVObject, error)
	Delete(ctx context.Context, key string) error
	DeleteAll(ctx context.Context) error
}

type KV

type KV struct {
	Options *Options
	// contains filtered or unexported fields
}

func New

func New(o *Options) (*KV, error)

func (*KV) Create

func (k *KV) Create(ctx context.Context, kvs []*protos.KVObject, overwrite bool) error

Create creates a kv object in RedisBackend. "overwrite" allows you to adjust create behavior - if set and the key already exists - it the method will overwrite the key. If not set and the key already exists - it will error.

Think of "overwrite" as an "upsert".

func (*KV) Delete

func (k *KV) Delete(ctx context.Context, key string) error

func (*KV) DeleteAll

func (k *KV) DeleteAll(ctx context.Context) error

DeleteAll will delete all kv entries by deleting and re-creating the bucket

func (*KV) Get

func (k *KV) Get(ctx context.Context, key string) (*protos.KVObject, error)

func (*KV) GetAll

func (k *KV) GetAll(ctx context.Context) ([]*protos.KVObject, error)

func (*KV) GetUsage

func (k *KV) GetUsage(ctx context.Context) (*Usage, error)

func (*KV) Update

func (k *KV) Update(ctx context.Context, kv *protos.KVObject) (*protos.KVObject, error)

Update updates a KV object. It WILL error if the key does not already exist.

type Options

type Options struct {
	RedisBackend *redis.Client
}

type Usage

type Usage struct {
	// This does NOT include history -- we get this value by doing Keys() on the
	// bucket
	NumItems int `json:"num_items"`

	// This includes history entries (ie. when you delete a KV, a copy of it is
	// kept around until the key is purged or the bucket is compacted)
	NumBytes int64 `json:"num_bytes"`
}

Jump to

Keyboard shortcuts

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