lock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(lock *RedisLock)

func WithAutoRenew

func WithAutoRenew() Option

WithAutoRenew 是否开启自动续期

func WithKey

func WithKey(key string) Option

WithKey 设置锁的key

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置锁过期时间

func WithToken

func WithToken(token string) Option

WithToken 设置锁的Token

type RedisLock

type RedisLock struct {
	context.Context
	*redis.Client
	// contains filtered or unexported fields
}

func (*RedisLock) Lock

func (lock *RedisLock) Lock() error

Lock 加锁

func (*RedisLock) Renew

func (lock *RedisLock) Renew() error

Renew 锁手动续期

func (*RedisLock) SpinLock

func (lock *RedisLock) SpinLock(timeout time.Duration) error

SpinLock 自旋锁

func (*RedisLock) UnLock

func (lock *RedisLock) UnLock() error

UnLock 解锁

type RedisLockInter

type RedisLockInter interface {
	// Lock 加锁
	Lock() error

	// UnLock 解锁
	UnLock() error

	// SpinLock 自旋锁
	SpinLock(timeout time.Duration) error

	// Renew 手动续期
	Renew() error
}

func New

func New(ctx context.Context, redisClient *redis.Client, lockKey string, options ...Option) RedisLockInter

Jump to

Keyboard shortcuts

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