etcdclient

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyEtcdLockProfile = keyEtcdProfile + "lock/"
	KeyEtcdLock        = KeyEtcdLockProfile + "%s"
)

Variables

View Source
var (
	ErrValueMayChanged = errors.New("The value has been changed by others on this time.")
	ErrEtcdNotInit     = errors.New("etcd is not initialized")
)

Functions

func DelLock

func DelLock(key string) error

func Delete

func Delete(key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

func Get

func Get(key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

func GetLock

func GetLock(key string, id clientv3.LeaseID) (bool, error)

func Grant

func Grant(ttl int64) (*clientv3.LeaseGrantResponse, error)

func IsValidAsKeyPath

func IsValidAsKeyPath(s string) bool

func NewEtcdTimeoutContext

func NewEtcdTimeoutContext() (context.Context, context.CancelFunc)

NewEtcdTimeoutContext return a new etcdTimeoutContext

func Put

func Put(key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

func PutWithModRev

func PutWithModRev(key, val string, rev int64) (*clientv3.PutResponse, error)

func PutWithTtl

func PutWithTtl(key, val string, ttl int64) (*clientv3.PutResponse, error)

func Watch

func Watch(key string, opts ...clientv3.OpOption) clientv3.WatchChan

Types

type Client

type Client struct {
	*clientv3.Client
	// contains filtered or unexported fields
}

func GetEtcd added in v1.1.2

func GetEtcd() *Client

func Init

func Init(endpoints []string, dialTimeout, reqTimeout int64) (*Client, error)

type ServerReg

type ServerReg struct {
	Client *Client

	//time-to-live
	Ttl int64
	// contains filtered or unexported fields
}

etcd服务注册并租约

func NewServerReg

func NewServerReg(ttl int64) *ServerReg

func (*ServerReg) Register

func (s *ServerReg) Register(key string, value string) error

func (*ServerReg) RevokeLease

func (s *ServerReg) RevokeLease() error

func (*ServerReg) Stop

func (s *ServerReg) Stop()

type Watcher

type Watcher interface {
	Watch() error

	Close() error
}

Jump to

Keyboard shortcuts

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