nx

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithExpire

func WithExpire(seconds int) func(*Options)

WithExpire 设置 Redis 缓存密钥过期时间

func WithInterval

func WithInterval(interval time.Duration) func(*Options)

WithInterval 设置重试间隔时间

func WithKey

func WithKey(key string) func(*Options)

WithKey 设置 Redis 缓存密钥

func WithRedis

func WithRedis(rd redis.UniversalClient) func(*Options)

WithRedis 设置 Redis 客户端

func WithRetry

func WithRetry(count int) func(*Options)

WithRetry 设置重试次数

Types

type Nx

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

func New

func New(options ...func(*Options)) (*Nx, error)

New 创建一个新的 nx 锁实例

func (*Nx) Lock

func (nx *Nx) Lock(ctx context.Context) error

Lock 尝试获取锁,如果获取失败,则在 interval 秒内自动重试 retry 次以获得锁定,如果失败,则返回错误

func (*Nx) Unlock

func (nx *Nx) Unlock(ctx context.Context) error

Unlock 释放锁

type Options

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

func (*Options) Validate

func (o *Options) Validate() error

Validate 校验 Options 结构体的参数是否合法

Jump to

Keyboard shortcuts

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