etcdutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Kv

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

func NewKv

func NewKv(prefix string, client *clientv3.Client) *Kv

NewKv creates a new Kv.

func (*Kv) Get

func (k *Kv) Get(ctx context.Context, key string) ([]byte, error)

Get gets the value of the key.

func (*Kv) GetNoCache

func (k *Kv) GetNoCache(ctx context.Context, key string) ([]byte, error)

GetNoCache gets the value of the key without using the cache.

func (*Kv) GetString

func (k *Kv) GetString(ctx context.Context, key string) (string, error)

GetString gets the value of the key.

func (*Kv) Handle

func (k *Kv) Handle(event *clientv3.Event)

Handle handles the etcd event.

func (*Kv) Len

func (k *Kv) Len() int

Len returns the number of entries in the cache.

func (*Kv) OnKeyChange

func (k *Kv) OnKeyChange(key string, hook func([]byte) error) bool

OnKeyChange registers a hook function to be called when the key changes. the key removed from etcd will not trigger the hook.

func (*Kv) Prefix

func (k *Kv) Prefix() string

Prefix returns the prefix of the keys.

func (*Kv) Preload

func (k *Kv) Preload(ctx context.Context) error

Preload loads all keys with the prefix into the cache.

func (*Kv) SetLogger

func (k *Kv) SetLogger(logger contract.Logger) *Kv

func (*Kv) UnsafeGet

func (k *Kv) UnsafeGet(ctx context.Context, key string) ([]byte, error)

UnsafeGet gets the value of the key. the []byte of return maybe not safe, if you want to use it for a long time, please copy it.

type Observer

type Observer interface {
	Prefix() string
	Handle(event *clientv3.Event)
}

type Watcher

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

func NewWatcher

func NewWatcher(client *clientv3.Client) *Watcher

func (*Watcher) Attach

func (e *Watcher) Attach(observer Observer)

Attach not goroutine safe

func (*Watcher) HasObserver

func (e *Watcher) HasObserver(prefix string) bool

HasObserver not goroutine safe

func (*Watcher) Run

func (e *Watcher) Run(ctx context.Context)

Run should exec after Attach

func (*Watcher) SetCommonPrefixMinLen

func (e *Watcher) SetCommonPrefixMinLen(l int) *Watcher

func (*Watcher) SetLogger

func (e *Watcher) SetLogger(logger contract.Logger) *Watcher

Jump to

Keyboard shortcuts

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