mutex

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockNil = errors.New("redlock: lock not acquired")

ErrLockNil 未获取到锁

Functions

This section is empty.

Types

type Mutex

type Mutex interface {
	// Lock 获取锁;未获取到会返回`ErrLockNil`
	Lock(ctx context.Context) error
	// TryLock 尝试获取锁;未获取到会返回`ErrLockNil`
	TryLock(ctx context.Context, attempts int, interval time.Duration) error
	// UnLock 释放锁
	UnLock(ctx context.Context) error
}

Mutex 分布式锁

func RedLock

func RedLock(cli *redis.Client, key string, ttl time.Duration) Mutex

RedLock 基于Redis实现的分布式锁实例

Jump to

Keyboard shortcuts

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