etcdtool

package
v0.0.0-...-8639602 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: BSL-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EtcdKeyDelete = "DELETE"
	EtcdKeyCreate = "CREATE"
	EtcdKeyModify = "MODIFY"
)

Variables

This section is empty.

Functions

func InitEtcd

func InitEtcd(cli *clientv3.Client)

Types

type DidChangeFunc

type DidChangeFunc func(status, key, value string)

监控一个key 发送变化 回调, status 取值 EtcdKeyDelete ,EtcdKeyCreate , EtcdKeyModify

type EtcdLock

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

func NewLocker

func NewLocker(lockKey string, timeout int) (locker *EtcdLock, cancelFunc func(), err error)

创建一把分布式锁

func (*EtcdLock) Lock

func (locker *EtcdLock) Lock(isWait bool) (err error)

锁住代码 isWait 是否阻塞等待锁释放

func (*EtcdLock) UnLock

func (locker *EtcdLock) UnLock() (err error)

释放锁

type EtcdTool

type EtcdTool struct {
	Tool *clientv3.Client
}

func GetEtcdTool

func GetEtcdTool() *EtcdTool

func (*EtcdTool) Delete

func (etcd *EtcdTool) Delete(key string) (err error)

func (*EtcdTool) DeletePrefix

func (etcd *EtcdTool) DeletePrefix(prefixKey string) (datas []string, err error)

func (*EtcdTool) Get

func (etcd *EtcdTool) Get(key string) (data string, err error)

失败返回err ,成功返回数据 或者空字符

func (*EtcdTool) GetPrefix

func (etcd *EtcdTool) GetPrefix(prefixKey string) (datas map[string]string, err error)

失败返回err ,成功返回数据 或者 返回nil

func (*EtcdTool) Put

func (etcd *EtcdTool) Put(key, value string) (err error)

put

func (*EtcdTool) PutWithLeaseId

func (etcd *EtcdTool) PutWithLeaseId(key, value string, leaseId int64) (err error)

put

func (*EtcdTool) PutWithTimeOut

func (etcd *EtcdTool) PutWithTimeOut(key, value string, timeout int) (err error)

put 值

func (*EtcdTool) RegistKeyAndKeepAlive

func (etcd *EtcdTool) RegistKeyAndKeepAlive(key, value string, ctx context.Context, callBack WatchHandleCallBack) (err error)

注册一个key 并且 使用租约保活

func (*EtcdTool) WatchKey

func (etcd *EtcdTool) WatchKey(watchKey string, ctx context.Context, changeFunc DidChangeFunc) (err error)

监控一个带前缀的key

func (*EtcdTool) WatchPrefix

func (etcd *EtcdTool) WatchPrefix(prefixKey string, ctx context.Context, changeFunc DidChangeFunc) (err error)

监控一个带前缀的key

type WatchHandleCallBack

type WatchHandleCallBack func(key string, leaseId int64, tool *EtcdTool)

leaseId 租约id ,保活使用

Jump to

Keyboard shortcuts

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