lock

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close 关闭构建器

func SetContextProvider added in v1.0.9

func SetContextProvider(provider ContextProvider)

SetContextProvider 设置 Context 提供者(由 dawn 包调用)

func SetMaker

func SetMaker(maker Maker)

SetMaker 设置Locker制造商

Types

type ContextProvider added in v1.0.9

type ContextProvider interface {
	// LockMaker 获取分布式锁制造器
	LockMaker() Maker
}

ContextProvider Context 提供者接口,用于避免循环依赖

func GetContextProvider added in v1.0.9

func GetContextProvider() ContextProvider

GetContextProvider 获取 Context 提供者

type Locker

type Locker interface {
	// Acquire 获取锁
	Acquire(ctx context.Context) error
	// TryAcquire 尝试获取锁
	TryAcquire(ctx context.Context, expiration ...time.Duration) error
	// Release 释放锁
	Release(ctx context.Context) error
}

func Make

func Make(name string) Locker

Make 制造一个Locker

type Maker

type Maker interface {
	// Make 制造一个Locker
	Make(name string) Locker
	// Close 关闭构建器
	Close() error
}

func GetMaker

func GetMaker() Maker

GetMaker 获取Locker制造商 优先从 Context 获取,如果没有关联 Context 则使用全局变量

type Option

type Option struct {
	Once       bool          // 是否仅获取一次;默认阻塞地获取,直到获取成功
	Expiration time.Duration //
}

Directories

Path Synopsis
redis module

Jump to

Keyboard shortcuts

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