com_distribute_lock

package
v0.0.0-...-3d4fdec Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockFailed 锁已被占用
	ErrLockFailed = errors.New("failed to acquire lock")
	// ErrUnlockFailed 释放锁失败
	ErrUnlockFailed = errors.New("failed to release lock")
)

Functions

This section is empty.

Types

type Etcd

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

func NewEtcd

func NewEtcd(client *clientv3.Client, opts ...EtcdOption) *Etcd

func (*Etcd) Lock

func (e *Etcd) Lock(ctx context.Context) (Unlock, error)

Lock 基于etcd实现分布式锁 获取锁失败会一直阻塞,直到获取到锁或获取锁超时

func (*Etcd) TryLock

func (e *Etcd) TryLock(ctx context.Context) (Unlock, error)

TryLock 如果获取不到锁,则立即返回 concurrency.ErrLocked

type EtcdOption

type EtcdOption func(*Etcd)

func WithEtcdKey

func WithEtcdKey(key string) EtcdOption

func WithEtcdTTL

func WithEtcdTTL(ttl int64) EtcdOption

type Redis

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

func NewRedis

func NewRedis(client *redis.Client, opts ...RedisOption) *Redis

func (*Redis) Lock

func (r *Redis) Lock(ctx context.Context) error

Lock 基于redis实现分布式锁 如果获取不到锁,则立即返回 ErrFailed

func (*Redis) LockContext

func (r *Redis) LockContext(ctx context.Context) error

LockContext 基于redis实现分布式锁 获取锁失败会一直阻塞,直到获取到锁或获取锁超时

func (*Redis) Unlock

func (r *Redis) Unlock(ctx context.Context) error

type RedisOption

type RedisOption func(*Redis)

func WithRedisDelayFunc

func WithRedisDelayFunc(f func() time.Duration) RedisOption

func WithRedisExpire

func WithRedisExpire(expire time.Duration) RedisOption

func WithRedisKey

func WithRedisKey(key string) RedisOption

func WithRedisTries

func WithRedisTries(tries int) RedisOption

func WithRedisValue

func WithRedisValue(value string) RedisOption

type Unlock

type Unlock func(ctx context.Context) error

Unlock 加锁时返回释放锁的函数

Jump to

Keyboard shortcuts

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