redsyncx

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockStopped 锁已停止错误
	ErrLockStopped = errors.New("锁已停止")
	// ErrLockNotAcquired 锁未获取错误
	ErrLockNotAcquired = errors.New("锁未获取")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// 锁名称
	LockName string
	// 锁过期时间
	Expiry time.Duration
	// 锁重试间隔时间
	RetryDelay time.Duration
	// 获取锁最大重试次数
	MaxRetries int
	// 续约间隔时间(默认过期时间的1/3)
	RenewalInterval time.Duration
	// 状态通道缓冲区大小
	StatusChanBuffer int
}

Config 锁配置

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认配置

type LockRedsync

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

LockRedsync 分布式锁重构版

func NewLockRedsync

func NewLockRedsync(redisClient []*redis.Client, logger logx.Loggerx, config Config) *LockRedsync

NewLockRedsync 创建分布式锁

func (*LockRedsync) CreateMutex

func (dl *LockRedsync) CreateMutex(name string) *redsync.Mutex

CreateMutex 创建一个新的 mutex 实例

func (*LockRedsync) GetLockInfo

func (dl *LockRedsync) GetLockInfo() map[string]interface{}

GetLockInfo 获取锁信息

func (*LockRedsync) IsLocked

func (dl *LockRedsync) IsLocked() bool

IsLocked 检查是否持有锁

func (*LockRedsync) Start

func (dl *LockRedsync) Start() <-chan LockResult

Start 启动锁服务 返回状态通道,用于接收锁状态变更通知

func (*LockRedsync) Status

func (dl *LockRedsync) Status() LockStatus

Status 获取当前锁状态

func (*LockRedsync) Stop

func (dl *LockRedsync) Stop()

Stop 停止锁服务,释放所有资源

type LockResult

type LockResult struct {
	Status LockStatus
	Error  error
}

LockResult 锁操作结果

type LockStatus

type LockStatus int

LockStatus 锁状态枚举

const (
	// LockStatusUnknown 锁未知状态
	LockStatusUnknown LockStatus = iota
	// LockStatusAcquired 锁已获取
	LockStatusAcquired
	// LockStatusLost 锁丢失
	LockStatusLost
	// LockStatusReleased 锁释放
	LockStatusReleased
)

type RedSyncIn

type RedSyncIn interface {
	Start() <-chan LockResult
	Stop()
	IsLocked() bool
	Status() LockStatus
	GetLockInfo() map[string]interface{}
	CreateMutex(name string) *redsync.Mutex
}

Directories

Path Synopsis
web

Jump to

Keyboard shortcuts

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