locker

package
v0.10.13 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockerPrefix = "_locker_"
)

Variables

View Source
var MaxLockerDuration time.Duration = 30 * time.Minute
View Source
var WaitInteval time.Duration = 50 * time.Millisecond

Functions

This section is empty.

Types

type Locker

type Locker interface {
	Lock(ctx context.Context, resource string) (Release, error)
	WaitForLocker(ctx context.Context, resource string, maxWait time.Duration, timeout time.Duration) (Release, error)
	LockWithtimeout(ctx context.Context, resource string, timeout time.Duration) (Release, error)
}

func InitRedisLocker added in v0.9.0

func InitRedisLocker(logger *zap.Logger, client *redis.Client) Locker

type RedisLocker added in v0.9.0

type RedisLocker struct {
	Logger *zap.Logger
	// contains filtered or unexported fields
}

func (*RedisLocker) Lock added in v0.9.0

func (r *RedisLocker) Lock(ctx context.Context, resource string) (Release, error)

func (*RedisLocker) LockWithtimeout added in v0.9.0

func (r *RedisLocker) LockWithtimeout(ctx context.Context, resource string, timeout time.Duration) (Release, error)

func (*RedisLocker) WaitForLocker added in v0.10.7

func (r *RedisLocker) WaitForLocker(ctx context.Context, resource string, maxWait time.Duration, timeout time.Duration) (Release, error)
func (r *RedisLocker) Init() {
	c := redis.NewClient(r.RedisOptions)
	r.client = c
	r.Logger.Info("redis locker ready.", zap.String("redis", r.RedisOptions.Addr))
}

type Release

type Release func(context.Context) error

Jump to

Keyboard shortcuts

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