dlock

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistributedLock

type DistributedLock struct {
	ID         int64     `xorm:"pk autoincr"`
	Name       string    `xorm:"varchar(255) notnull unique"`
	LockCode   string    `xorm:"varchar(36) notnull"`
	ExpireTime time.Time `xorm:"notnull"`
	CreatedAt  time.Time `xorm:"created notnull"`
}

锁存储结构

type DistributedLockManager

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

分布式锁管理器

func NewDistributedLockManager

func NewDistributedLockManager(config LockManagerConfig) (*DistributedLockManager, error)

创建新的分布式锁管理器

func (*DistributedLockManager) Close

func (dlm *DistributedLockManager) Close()

关闭锁管理器

func (*DistributedLockManager) Lock

func (dlm *DistributedLockManager) Lock(ctx context.Context, lockName string, opts ...LockOption) (string, error)

阻塞方式获取锁

func (*DistributedLockManager) Renew

func (dlm *DistributedLockManager) Renew(ctx context.Context, lockName, lockCode string, ttl time.Duration) error

续期锁

func (*DistributedLockManager) Unlock

func (dlm *DistributedLockManager) Unlock(lockName, lockCode string) error

解锁

type LockManagerConfig

type LockManagerConfig struct {
	RetryInterval      time.Duration // 重试间隔,默认 100ms
	DefaultAcquireWait time.Duration // 默认获取锁等待时间,默认 10s
	DefaultLockTTL     time.Duration // 默认锁生存时间,默认 30s
	CleanupInterval    time.Duration // 清理间隔,默认 1分钟
	MaxAcquireRetries  int           // 最大重试次数,0表示无限次
	CleanupBatchSize   int           // 批量清理数量,默认 100
}

锁管理器配置

type LockOption

type LockOption interface {
	// contains filtered or unexported methods
}

锁选项接口

func WithTTLOption

func WithTTLOption(ttl time.Duration) LockOption

实用选项函数

func WithWaitOption

func WithWaitOption(wait time.Duration) LockOption

type WithTTL

type WithTTL time.Duration

锁TTL选项

type WithWait

type WithWait time.Duration

锁等待时间选项

Jump to

Keyboard shortcuts

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