zetcd

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 11 Imported by: 0

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)

func Close

func Close(client *clientv3.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. To avoid accumulating an infinite amount of historical data, it is important to compress past revisions. After compaction, etcd deletes historical revisions, freeing resources for future use. The superseded data of all revisions prior to the compressed revision will be inaccessible.

func CreateLease

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

func Delete

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

func DeleteFromKey

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

DeleteFromKey Removes all key-value pairs that key match >= given key (using byte comparison).

func DeletePrefix

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

func DeleteRange

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

DeleteRange delete key-value which key in range of [startKey, endKey).

func Get

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

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 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 GetWithLimit

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

func GetWithPrefix

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

func GetWithRange

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

GetWithRange get keys which in [startKey, endKey).

func GetWithRevision

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

func GetWithSorted

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

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)

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
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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