etcdcli

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close 关闭连接

func Connect

func Connect(servers []string, options ...Option)

Connect 连接etcd

func Get

func Get(ctx context.Context, key string) (val string, isNotExist bool, err error)

Get 根据key获取value

func Put

func Put(ctx context.Context, key, value string, ttl int64) (err error)

Put 设置key, ttl为租约期, 单位为秒

func UnlockAndClose

func UnlockAndClose(ctx context.Context, lock *Locker) (err error)

UnlockAndClose 解锁和关锁

Types

type Locker

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

func NewLocker

func NewLocker(ttl int) (l *Locker, err error)

NewLocker 创建一个锁

func NewLockerAndLock

func NewLockerAndLock(ctx context.Context, lockKey string, ttl int) (lock *Locker, err error)

NewLockerAndLock 新建锁+锁key

func (*Locker) Close

func (l *Locker) Close() (err error)

Close 调用NewLocker后必须调用此方法

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, key string) (err error)

Lock 阻塞式获取锁,锁被占用时则阻塞等待

func (*Locker) TryLock

func (l *Locker) TryLock(ctx context.Context, key string) (err error)

TryLock 尝试式获取锁,锁被占用时则立即返回err

func (*Locker) UnLock

func (l *Locker) UnLock(ctx context.Context) (err error)

UnLock 解锁

type Option

type Option func(*Options)

func WithPingKeyPrefix

func WithPingKeyPrefix(prefix string) Option

WithPingKeyPrefix 设置ping key的前缀

func WithUserAndPass

func WithUserAndPass(user, pwd string) Option

WithUserAndPass 设置用户名密码

type Options

type Options struct {
	Username string
	Password string

	PingKeyPrefix string
}

Jump to

Keyboard shortcuts

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