locker

package
v0.0.0-...-bc76e52 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotNeedLockError = errors.New("need not lock")

Functions

func DoubleLockUtil

func DoubleLockUtil(ctx context.Context, key string, locker Locker, doCheck, operation func() error) error

二重判定锁

func SingleLockUtil

func SingleLockUtil(ctx context.Context, key string, locker Locker, doCheck, operation func() error) error

一重判定锁

Types

type Locker

type Locker interface {
	Lock(name string) error
	Unlock(name string) error
}

func NewRedisLocker

func NewRedisLocker(redis *redisext.RedisExt, ttl time.Duration) Locker

type Lockers

type Lockers struct {
	Redis *redisext.RedisExt
	Rd    *rand.Rand
}

func NewLockers

func NewLockers(redis *redisext.RedisExt, rd *rand.Rand) *Lockers

func (*Lockers) Lock

func (l *Lockers) Lock(ctx context.Context, fun, lockKey string, lockTime time.Duration) (int32, error)

func (*Lockers) LockCyclic

func (l *Lockers) LockCyclic(ctx context.Context, fun, lockKey string, lockTime time.Duration) (int32, error)

循环等待获取锁

func (*Lockers) UnLock

func (l *Lockers) UnLock(ctx context.Context, lockKey string, value int32, fun string)

type RedisLocker

type RedisLocker struct {
	Redis *redisext.RedisExt
	// contains filtered or unexported fields
}

func (*RedisLocker) Lock

func (r *RedisLocker) Lock(key string) error

func (*RedisLocker) Unlock

func (r *RedisLocker) Unlock(key string) error

Jump to

Keyboard shortcuts

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