etcd

package
v0.0.0-...-2692626 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TtlSecondDefault    int64  = 33 //默认TTL时间 秒
	WatchMsgTypeService string = "service"
	WatchMsgTypeCommand string = "command"
)

Variables

This section is empty.

Functions

func GenerateServiceKey

func GenerateServiceKey(projectName string, zoneID uint32, serviceName string, serviceID uint32) string

GenerateServiceKey 生成服务注册的key

func GenerateWatchCommandPrefix

func GenerateWatchCommandPrefix(projectName string, zoneID uint32, serviceName string) string

GenerateWatchCommandPrefix 生成关注命令的前缀

func GenerateWatchServicePrefix

func GenerateWatchServicePrefix(projectName string) string

GenerateWatchServicePrefix 生成关注服务的前缀

func Parse

func Parse(key string) (msgType string, zoneID string, serviceName string, serviceID string)

Parse e.g.:${objectName}/service/${zoneID}/${serviceName}/${serviceID} e.g.:${objectName}/command/${zoneID}/${serviceName}/${serviceID}

Types

type KV

type KV struct {
	Key   string
	Value string
}

KV key-value pair

type Mgr

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

Mgr 管理器

func (*Mgr) Del

func (p *Mgr) Del(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

Del 删除

func (*Mgr) DelRange

func (p *Mgr) DelRange(ctx context.Context, startKeyPrefix string, endKeyPrefix string) (*clientv3.DeleteResponse, error)

DelRange 按选项删除范围内的键值

func (*Mgr) DelWithPrefix

func (p *Mgr) DelWithPrefix(ctx context.Context, keyPrefix string) (*clientv3.DeleteResponse, error)

DelWithPrefix 删除键值 匹配的键值

func (*Mgr) Get

func (p *Mgr) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

Get 检索键

func (*Mgr) GetPrefix

func (p *Mgr) GetPrefix(ctx context.Context, key string) (*clientv3.GetResponse, error)

GetPrefix 查找以key为前缀的所有 key value

func (*Mgr) GetPrefixSendIntoChan

func (p *Mgr) GetPrefixSendIntoChan(ctx context.Context, preFix string) error

GetPrefixSendIntoChan 取得关心的前缀,放入 chan 中

func (*Mgr) Handler

func (p *Mgr) Handler(key string, val string) error

Handler etcd 处理数据

func (*Mgr) Put

func (p *Mgr) Put(ctx context.Context, key string, value string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

Put 将一个键值对放入etcd中

func (*Mgr) PutWithLease

func (p *Mgr) PutWithLease(ctx context.Context, key string, value string) (*clientv3.PutResponse, error)

PutWithLease 将一个键值对放入etcd中 WithLease 带ttl

func (*Mgr) Run

func (p *Mgr) Run(ctx context.Context) error

Run 租约续约

func (*Mgr) Start

func (p *Mgr) Start(ctx context.Context, opts ...*Options) error

Start 开始

func (*Mgr) Stop

func (p *Mgr) Stop() error

Stop 停止

func (*Mgr) Watch

func (p *Mgr) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan

Watch 监视key

func (*Mgr) WatchPrefix

func (p *Mgr) WatchPrefix(ctx context.Context, key string) clientv3.WatchChan

WatchPrefix 监视以key为前缀的所有 key value

func (*Mgr) WatchPrefixSendIntoChan

func (p *Mgr) WatchPrefixSendIntoChan(ctx context.Context, preFix string) error

WatchPrefixSendIntoChan 监听key变化,放入 chan 中

type OnFunc

type OnFunc func(key string, value string) error

OnFunc 处理数据

type Options

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

Options contains Options to configure instance. Each option can be set through setter functions. See documentation for each setter function for an explanation of the option.

func NewOptions

func NewOptions() *Options

NewOptions 新的Options

func (*Options) WithAddrs

func (p *Options) WithAddrs(addrs []string) *Options

func (*Options) WithDialTimeout

func (p *Options) WithDialTimeout(dialTimeout time.Duration) *Options

func (*Options) WithGrantLeaseMaxRetries

func (p *Options) WithGrantLeaseMaxRetries(retries int) *Options

func (*Options) WithKV

func (p *Options) WithKV(kv []KV) *Options

func (*Options) WithOnFunc

func (p *Options) WithOnFunc(onFunc OnFunc) *Options

func (*Options) WithOutgoingEventChan

func (p *Options) WithOutgoingEventChan(eventChan chan<- interface{}) *Options

func (*Options) WithTTL

func (p *Options) WithTTL(ttl int64) *Options

func (*Options) WithWatchCommandPrefix

func (p *Options) WithWatchCommandPrefix(watchCommandPrefix string) *Options

func (*Options) WithWatchServicePrefix

func (p *Options) WithWatchServicePrefix(watchServicePrefix string) *Options

Jump to

Keyboard shortcuts

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