ezetcd

package module
v0.0.0-...-2bcf145 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 11 Imported by: 0

README

ezetcd

A etcd operate client library based on golang

Documentation

Index

Constants

View Source
const (
	DefaultDialTimeout          = time.Duration(2000) * time.Millisecond
	DefaultDialKeepAlivePeriod  = time.Duration(10000) * time.Millisecond
	DefaultDialKeepAliveTimeout = time.Duration(3000) * time.Millisecond
)

默认配置

View Source
const (
	MethodCreate = "create"
	MethodModify = "modify"
	MethodDelete = "delete"
)

操作类型

Variables

This section is empty.

Functions

func Client

func Client(config Config) (*clientv3.Client, error)

Client 获取etcd client.

func Close

func Close(client *clientv3.Client)

Close 关闭etcd client.

func Compact

func Compact(ctx context.Context, client *clientv3.Client, version int64) (response *clientv3.CompactResponse, err error)

Compact compacts etcd KV history before the given rev. (为了避免积累无限数量的历史数据,压缩过往的修订版本功能很重要。 压缩之后,etcd删除历史修订版本,释放资源来提供未来使用。 所有修订版本在压缩修订版本之前的被替代的数据将不可访问).

func CreateLease

func CreateLease(ctx context.Context, client *clientv3.Client, leaseTTL int64) (*clientv3.LeaseGrantResponse, clientv3.LeaseID, error)

CreateLease create a lease id.

func Delete

func Delete(ctx context.Context, client *clientv3.Client, key string) (*clientv3.DeleteResponse, error)

Delete 删除一个key-value对.

func DeleteFromKey

func DeleteFromKey(ctx context.Context, client *clientv3.Client, key string) (*clientv3.DeleteResponse, error)

DeleteFromKey 删除所有匹配>=给定key(使用byte比较)的key-value对.

func DeletePrefix

func DeletePrefix(ctx context.Context, client *clientv3.Client, key string) (*clientv3.DeleteResponse, error)

DeletePrefix 删除所有前缀匹配要求的key-value对.

func DeleteRange

func DeleteRange(ctx context.Context, client *clientv3.Client, startKey string, endKey string) (*clientv3.DeleteResponse, error)

DeleteRange 删除所有匹配[startKey, endKey)的key-value对.

func Get

func Get(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

Get 获取key对应的value.

func GetCountOnly

func GetCountOnly(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetCountOnly get keys return only the count of keys.

func GetFirst

func GetFirst(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetFirst gets the lexically first key in the request range.

func GetFirstCrt

func GetFirstCrt(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetFirstCrt gets the key with the oldest creation revision in the request range.

func GetFirstRevision

func GetFirstRevision(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetFirstRevision gets the key with the oldest modification revision in the request range.

func GetFromKey

func GetFromKey(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetFromKey get keys that are greater than or equal to the given key using byte compare.

func GetKeysOnly

func GetKeysOnly(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetKeysOnly get key return only the keys and the corresponding values will be omitted.

func GetLast

func GetLast(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetLast gets the lexically last key in the request range.

func GetLastCrt

func GetLastCrt(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetLastCrt gets the key with the latest creation revision in the request range.

func GetLastRevision

func GetLastRevision(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetLastRevision gets the key with the latest modification revision in the request range.

func GetLimit

func GetLimit(ctx context.Context, client *clientv3.Client, key string, num int64) (*clientv3.GetResponse, map[string]string, error)

GetLimit 获取限定最大数量的key-value对.

func GetMaxCrtRevision

func GetMaxCrtRevision(ctx context.Context, client *clientv3.Client, key string, revision int64) (*clientv3.GetResponse, map[string]string, error)

GetMaxCrtRevision get key filters out keys for Get with creation revisions greater than the given revision.

func GetMaxModRevision

func GetMaxModRevision(ctx context.Context, client *clientv3.Client, key string, revision int64) (*clientv3.GetResponse, map[string]string, error)

GetMaxModRevision get key filters out keys for Get with modification revisions greater than the given revision.

func GetMinCrtRevision

func GetMinCrtRevision(ctx context.Context, client *clientv3.Client, key string, revision int64) (*clientv3.GetResponse, map[string]string, error)

GetMinCrtRevision get key filters out keys for Get with creation revisions less than the given revision.

func GetMinModRevision

func GetMinModRevision(ctx context.Context, client *clientv3.Client, key string, revision int64) (*clientv3.GetResponse, map[string]string, error)

GetMinModRevision get key filters out keys for Get with modification revisions less than the given revision.

func GetPrefix

func GetPrefix(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetPrefix 获取所有前缀匹配key的key-value对.

func GetRange

func GetRange(ctx context.Context, client *clientv3.Client, startKey string, endKey string) (*clientv3.GetResponse, map[string]string, error)

GetRange get keys which in [startKey, endKey).

func GetRevision

func GetRevision(ctx context.Context, client *clientv3.Client, key string, revision int64) (*clientv3.GetResponse, map[string]string, error)

GetRevision 获取制定revision的key-value对.

func GetWithSorted

func GetWithSorted(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

GetWithSorted 获取前缀匹配key的key-value对,结果已排序.

func KeepAliveAways

func KeepAliveAways(ctx context.Context, client *clientv3.Client, leaseID clientv3.LeaseID) (<-chan *clientv3.LeaseKeepAliveResponse, error)

KeepAliveAways keep a lease aways.

func KeepAliveOnce

func KeepAliveOnce(ctx context.Context, client *clientv3.Client, leaseID clientv3.LeaseID) (*clientv3.LeaseKeepAliveResponse, error)

KeepAliveOnce keep a lease once.

func LeaseTimeToLive

func LeaseTimeToLive(ctx context.Context, client *clientv3.Client, leaseID clientv3.LeaseID) (*clientv3.LeaseTimeToLiveResponse, map[string]string, error)

LeaseTimeToLive retrieves the lease information of the given lease ID.

func Put

func Put(ctx context.Context, client *clientv3.Client, key string, value string) (*clientv3.PutResponse, error)

Put a key-value pair.

func PutWithLease

func PutWithLease(ctx context.Context, client *clientv3.Client, key string, value string, leaseID clientv3.LeaseID) (*clientv3.PutResponse, error)

PutWithLease a key-value pair with lease.

func RevokeLease

func RevokeLease(ctx context.Context, client *clientv3.Client, leaseID clientv3.LeaseID) (*clientv3.LeaseRevokeResponse, error)

RevokeLease revoke a lease. 撤销租约,等同于租约到期,关联的节点都会被删除

func TxnDelete

func TxnDelete(ctx context.Context, client *clientv3.Client, KVList map[string]string) (*clientv3.TxnResponse, error)

TxnDelete txn multi delete.

func TxnPut

func TxnPut(ctx context.Context, client *clientv3.Client, KVList map[string]string) (*clientv3.TxnResponse, error)

TxnPut txn multi write.

func TxnPutWithLease

func TxnPutWithLease(ctx context.Context, client *clientv3.Client, KVList map[string]string, leaseID clientv3.LeaseID) (*clientv3.TxnResponse, error)

TxnPutWithLease txn multi lease.

func Watch

func Watch(ctx context.Context,
	client *clientv3.Client,
	key string,
	data chan WatchData,
	stopCh chan struct{})

Watch a key change event.

func WatchPrefix

func WatchPrefix(ctx context.Context,
	client *clientv3.Client,
	key string,
	data chan WatchData,
	stopCh chan struct{})

WatchPrefix a prefix key change event.

func WatchRange

func WatchRange(ctx context.Context,
	client *clientv3.Client,
	keyOne string,
	keyTwo string,
	data chan WatchData,
	stopCh chan struct{})

WatchRange a key range change event.

func WatchWithProgressNotify

func WatchWithProgressNotify(ctx context.Context, client *clientv3.Client, key string, data chan WatchData)

WatchWithProgressNotify with progress notify ???

Types

type Config

type Config struct {
	NodeList             []string      `json:"nodeList"`
	UseTLS               bool          `json:"userTLS"`
	CaFile               string        `json:"ca"`
	CertFile             string        `json:"cert"`
	CertKeyFile          string        `json:"key"`
	ServerName           string        `json:"serverName"`
	DialTimeout          time.Duration `json:"timeout"`          // per - Millisecond
	DialKeepAlivePeriod  time.Duration `json:"keepAlivePeriod"`  // per - Millisecond
	DialKeepAliveTimeout time.Duration `json:"keepAliveTimeout"` // per - Millisecond
}

Config etcd配置

type Locker

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

Locker 分布式锁

func NewLocker

func NewLocker(client *clientv3.Client, lock string, ttl int, owner string) *Locker

func (*Locker) Close

func (l *Locker) Close() error

func (*Locker) Init

func (l *Locker) Init() error

func (*Locker) IsCurLockAtMe

func (l *Locker) IsCurLockAtMe(ctx context.Context) (bool, error)

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context) error

func (*Locker) TryLock

func (l *Locker) TryLock(ctx context.Context) error

func (*Locker) Unlock

func (l *Locker) Unlock(ctx context.Context) error

type WatchData

type WatchData struct {
	Operate string
	Vision  int64
	Key     string
	Value   string
}

WatchData watch获取的数据对象

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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