kv

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnwrapValues added in v0.0.28

func UnwrapValues[T MarshalerUnmarshaler](ctx context.Context, in <-chan WatchValue[T], errs <-chan error) (<-chan T, <-chan error, error)

func WithNoErrorOnNotFound added in v0.0.30

func WithNoErrorOnNotFound(ctx context.Context) context.Context

func WithPurge added in v0.0.32

func WithPurge(ctx context.Context) context.Context

func WithStopOnZero added in v0.0.28

func WithStopOnZero(ctx context.Context) context.Context

Types

type KeyValue

type KeyValue[T MarshalerUnmarshaler] struct {
	// contains filtered or unexported fields
}

func (*KeyValue[T]) Create

func (s *KeyValue[T]) Create(ctx context.Context, key string, value T) (revision uint64, err error)

func (*KeyValue[T]) Delete

func (s *KeyValue[T]) Delete(ctx context.Context, key string, opts ...nats.DeleteOpt) error

func (*KeyValue[T]) Get

func (s *KeyValue[T]) Get(ctx context.Context, key string) (T, uint64, error)

func (*KeyValue[T]) GetAll

func (s *KeyValue[T]) GetAll(ctx context.Context, keys []string) ([]T, error)

func (*KeyValue[T]) Keys

func (s *KeyValue[T]) Keys(ctx context.Context) ([]string, error)

func (*KeyValue[T]) LastRevision

func (s *KeyValue[T]) LastRevision(ctx context.Context, key string) (uint64, error)

func (*KeyValue[T]) Put

func (s *KeyValue[T]) Put(ctx context.Context, key string, value T) (revision uint64, err error)

func (*KeyValue[T]) Update

func (s *KeyValue[T]) Update(ctx context.Context, key string, value T, lastRevision uint64) (revision uint64, err error)

func (*KeyValue[T]) Watch added in v0.0.28

func (s *KeyValue[T]) Watch(ctx context.Context, sub string, opts ...nats.WatchOpt) (<-chan WatchValue[T], <-chan error, error)

func (*KeyValue[T]) WatchAll added in v0.0.28

func (s *KeyValue[T]) WatchAll(ctx context.Context, opts ...nats.WatchOpt) (<-chan WatchValue[T], <-chan error, error)

type KeyValuer

type KeyValuer[T MarshalerUnmarshaler] interface {
	Keys(ctx context.Context) ([]string, error)
	Get(ctx context.Context, key string) (T, uint64, error)
	GetAll(ctx context.Context, keys []string) ([]T, error)
	Create(ctx context.Context, key string, value T) (revision uint64, err error)
	Put(ctx context.Context, key string, value T) (revision uint64, err error)
	Update(ctx context.Context, key string, value T, lastRevision uint64) (revision uint64, err error)
	// Status(ctx context.Context, key string) (nats.KeyValueStatus, error)
	LastRevision(context.Context, string) (uint64, error)
	Delete(ctx context.Context, key string, opts ...nats.DeleteOpt) error
	WatchAll(ctx context.Context, opts ...nats.WatchOpt) (<-chan WatchValue[T], <-chan error, error)
	Watch(ctx context.Context, sub string, opts ...nats.WatchOpt) (<-chan WatchValue[T], <-chan error, error)
}

func BucketKeyValuer added in v0.0.3

func BucketKeyValuer[T MarshalerUnmarshaler](conn *nats.Conn, name string) (KeyValuer[T], error)

func New

func New[T MarshalerUnmarshaler](kv nats.KeyValue) KeyValuer[T]

type Marshaler

type Marshaler interface {
	MarshalValue() ([]byte, error)
}

A Marshaler can encode itself into bytes. aggregates must implement Marshaler & Unmarshaler for Snapshots to work.

Example using encoding/gob:

type foo struct {
	aggregate.Aggregate
	state
}

type state struct {
	Name string
	Age uint8
}

func (f *foo) MarshalValue() ([]byte, error) {
	var buf bytes.Buffer
	err := gob.NewEncoder(&buf).Encode(f.state)
	return buf.Bytes(), err
}

func (f *foo) UnmarshalValue(p []byte) error {
	return gob.NewDecoder(bytes.NewReader(p)).Decode(&f.state)
}

type MarshalerUnmarshaler

type MarshalerUnmarshaler interface {
	Marshaler
	Unmarshaler
}

type NilValue

type NilValue struct{}

func (*NilValue) MarshalValue

func (*NilValue) MarshalValue() ([]byte, error)

func (*NilValue) UnmarshalValue

func (*NilValue) UnmarshalValue([]byte) error

type Op added in v0.0.31

type Op = nats.KeyValueOp

type StringValue

type StringValue struct {
	Value string `json:"value"`
}

func (*StringValue) MarshalValue

func (v *StringValue) MarshalValue() ([]byte, error)

func (*StringValue) UnmarshalValue

func (v *StringValue) UnmarshalValue(b []byte) error

type UInt64Value

type UInt64Value struct {
	Value uint64 `json:"value"`
}

func (*UInt64Value) MarshalValue

func (v *UInt64Value) MarshalValue() ([]byte, error)

func (*UInt64Value) UnmarshalValue

func (v *UInt64Value) UnmarshalValue(b []byte) error

type Unmarshaler

type Unmarshaler interface {
	UnmarshalValue([]byte) error
}

An Unmarshaler can decode itself from bytes.

type WatchValue added in v0.0.28

type WatchValue[T MarshalerUnmarshaler] struct {
	Op    Op
	Value T
	Key   string
}

Jump to

Keyboard shortcuts

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