lock

package
v0.0.18-test Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedisLockKey redis lock key
	RedisLockKey = "eagle:redis:lock:%s"
	// EtcdLockKey etcd lock key
	EtcdLockKey = "/eagle/lock/%s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdLock

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

EtcdLock define a etcd lock

func NewEtcdLock

func NewEtcdLock(client *v3.Client, key string, ttl int) (mutex *EtcdLock, err error)

NewEtcdLock create a etcd lock ttl for lease

func (*EtcdLock) Lock

func (l *EtcdLock) Lock(ctx context.Context) (b bool, err error)

Lock acquires the lock.

func (*EtcdLock) Unlock

func (l *EtcdLock) Unlock(ctx context.Context) (b bool, err error)

Unlock release a lock.

type Lock

type Lock interface {
	Lock(ctx context.Context) (bool, error)
	Unlock(ctx context.Context) (bool, error)
}

Lock define common func

type RedisLock

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

RedisLock is a redis lock.

func NewRedisLock

func NewRedisLock(rdb *redis.Client, key string, expiration time.Duration) *RedisLock

NewRedisLock new a redis lock instance nolint

func (*RedisLock) Lock

func (l *RedisLock) Lock(ctx context.Context) (bool, error)

Lock acquires the lock.

func (*RedisLock) Unlock

func (l *RedisLock) Unlock(ctx context.Context) (bool, error)

Unlock del the lock. NOTE: token 一致才会执行删除,避免误删,这里用了lua脚本进行事务处理

Jump to

Keyboard shortcuts

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