lock

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock interface {
	Lock(ctx context.Context) (bool, error)
	Unlock(ctx context.Context) (bool, error)
}

Lock define common func

type Option

type Option func(l *RedisLock)

Option RedisLock option

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix with prefix

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL with ttl

type RedisLock

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

RedisLock is a redis lock.

func NewRedisLock

func NewRedisLock(rdb *redis.Client, key string, opts ...Option) *RedisLock

NewRedisLock new a redis lock instance

func (*RedisLock) Lock

func (l *RedisLock) Lock(ctx context.Context) (bool, error)

Lock acquires the lock.

func (*RedisLock) Unlock

func (l *RedisLock) Unlock(ctx context.Context) (bool, error)

Unlock del the lock. NOTE: token 一致才会执行删除,避免误删,这里用了lua脚本进行事务处理

Jump to

Keyboard shortcuts

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