etcd

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeLocker added in v0.4.10

func InitializeLocker(config *clientv3.Config) error

配置分布式锁

Types

type DistributeLock added in v0.4.10

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

Etcd 分布式锁

var Locker *DistributeLock

func NewDistributeLock added in v0.4.10

func NewDistributeLock(config clientv3.Config) (*DistributeLock, error)

NewDistributeLock creates a new DistributeLock

func (*DistributeLock) Lock added in v0.4.10

func (d *DistributeLock) Lock(prefix string) (cancel func(), err1 error)

Lock 尝试获得锁(阻塞)

func (*DistributeLock) TryLock added in v0.4.10

func (d *DistributeLock) TryLock(prefix string) (cancel func(), err1 error)

TryLock 尝试获得锁(非阻塞)

type Node

type Node struct {
	// Id 编号
	Id uint32 `json:"id"`
	// Addr 地址
	Addr string `json:"addr"`
}

节点

type Registry

type Registry interface {
	// Register 创建租期/注册节点,返回租期ID和错误, 如果IP为空,则默认为第一个网卡首个IP
	Register(ip string, port int) (clientv3.LeaseID, error)
	// Revoke 撤销租期/注销节点
	Revoke(LeaseID int64) error
	// Stop 停止节点监测
	Stop()
}

func NewRegistry

func NewRegistry(service string, ttl int64, config clientv3.Config) (Registry, error)

NewRegistry 创建服务注册, ttl租约时间

type SelectAlgorithm

type SelectAlgorithm int
const AlgRandom SelectAlgorithm = 0
const AlgRoundRobin SelectAlgorithm = 1

type Selector

type Selector interface {
	Next() (Node, error)
}

func NewSelector

func NewSelector(name string, config clientv3.Config, alg SelectAlgorithm) (Selector, error)

Jump to

Keyboard shortcuts

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