store

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Callback

type Callback func(ev *Event)

type Event

type Event struct {
	Type EventType
	Data *KV
	Prev *KV
}

type EventType

type EventType int
const (
	PUT    EventType = 0
	DELETE EventType = 1
)

type KV

type KV struct {
	Key            string
	Value          []byte
	CreateRevision int64
	ModifyRevision int64
	Version        int64
}

type Option

type Option func(*Options)

func KeyOnly

func KeyOnly() Option

func Prefix

func Prefix() Option

func Revision

func Revision(r int64) Option

type Options

type Options struct {
	Prefix   bool  // Delete,Watch use
	KeyOnly  bool  // Get,List
	Revision int64 // Get,List
}

func (*Options) Build

func (o *Options) Build(opts ...Option)

type Store

type Store interface {
	Name() string
	List(ctx context.Context, key string, opts ...Option) ([]*KV, error)
	Get(ctx context.Context, key string, opts ...Option) (*KV, error)
	Put(ctx context.Context, key string, value []byte) error
	Delete(ctx context.Context, key string, opts ...Option) error
	Exists(ctx context.Context, key string) (bool, error)
	Watch(ctx context.Context, key string, cb Callback, opts ...Option) error
	Close() error
}

Store kv storage 主要用途:配置文件管理 推荐使用etcd,拥有mvcc控制 可以是本地文件存储,也可以是分布式kv存储,如etcd,consul,zookeeper consul的value限制不超过512kb

Key需要保持路径一样的形式,例如:path/to/key Get:通过Key查询是否有数据,没有数据返回nil List:通过前缀查询,空返回全部 Put: 通过key写入数据 Delete: 通过Key删除数据,如果有额外参数Prefix,则表示前缀匹配所有 Exists: 通过key判断是否存在 Watch: 监听key变化,如果有额外参数Prefix,则表示前缀匹配(监听目录) 注意: Get或者List查找不到数据时,会返回ErrNotFound错误

https://github.com/abronan/valkeyrie https://etcd.io/ https://www.consul.io/docs/agent/kv.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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