distributedlock

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCodeLockNotAutoExtended = "LOCK_NOT_AUTO_EXTENDED"

Functions

This section is empty.

Types

type BaseDistributedLock

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

func (*BaseDistributedLock) Expiration

func (dl *BaseDistributedLock) Expiration() time.Time

func (*BaseDistributedLock) ExtendedCount

func (dl *BaseDistributedLock) ExtendedCount() int

func (*BaseDistributedLock) Resource

func (dl *BaseDistributedLock) Resource() string

func (*BaseDistributedLock) TTL

func (dl *BaseDistributedLock) TTL() time.Duration

type DistributedLock

type DistributedLock interface {
	Resource() string
	TTL() time.Duration
	Expiration() time.Time
	ExtendedCount() int

	Lock(ctx context.Context) error
	TryLock(ctx context.Context) (bool, error)
	Unlock(ctx context.Context) error

	Extend(ctx context.Context) (bool, error)
	AutoExtend(ctx context.Context) (context.Context, error)
}

type DistributedPostgresLock

type DistributedPostgresLock struct {
	BaseDistributedLock
}

func NewDistributedPostgresLock

func NewDistributedPostgresLock(resource string, ttl time.Duration) *DistributedPostgresLock

func (*DistributedPostgresLock) AutoExtend

func (*DistributedPostgresLock) Extend

func (l *DistributedPostgresLock) Extend(ctx context.Context) (bool, error)

func (*DistributedPostgresLock) Lock

func (*DistributedPostgresLock) TryLock

func (l *DistributedPostgresLock) TryLock(ctx context.Context) (locked bool, err error)

func (*DistributedPostgresLock) Unlock

type DistributedRedisLock

type DistributedRedisLock struct {
	BaseDistributedLock
	// contains filtered or unexported fields
}

func NewDistributedRedisLock

func NewDistributedRedisLock(redis redis.Redis, resource string, ttl time.Duration) *DistributedRedisLock

func (*DistributedRedisLock) AutoExtend

func (l *DistributedRedisLock) AutoExtend(ctx context.Context) (context.Context, error)

func (*DistributedRedisLock) Extend

func (l *DistributedRedisLock) Extend(ctx context.Context) (bool, error)

func (*DistributedRedisLock) Lock

Lock will block until the lock is acquired or an error occurs.

func (*DistributedRedisLock) TryLock

func (l *DistributedRedisLock) TryLock(ctx context.Context) (bool, error)

TryLock will attempt to acquire the lock and return true if successful.

func (*DistributedRedisLock) Unlock

func (l *DistributedRedisLock) Unlock(ctx context.Context) error

type Factory

type Factory interface {
	NewDistributedLock(resource string, ttl time.Duration) DistributedLock
}

type LocalFactory

type LocalFactory struct {
}

func NewLocalFactory

func NewLocalFactory() *LocalFactory

func (*LocalFactory) NewDistributedLock

func (f *LocalFactory) NewDistributedLock(resource string, ttl time.Duration) DistributedLock

type LocalLock

type LocalLock struct {
	BaseDistributedLock
	// contains filtered or unexported fields
}

func NewDistributedLocalLock

func NewDistributedLocalLock(resource string, ttl time.Duration) *LocalLock

func (*LocalLock) AutoExtend

func (l *LocalLock) AutoExtend(ctx context.Context) (context.Context, error)

func (*LocalLock) Extend

func (l *LocalLock) Extend(ctx context.Context) (bool, error)

func (*LocalLock) Lock

func (l *LocalLock) Lock(ctx context.Context) error

func (*LocalLock) TryLock

func (l *LocalLock) TryLock(ctx context.Context) (bool, error)

func (*LocalLock) Unlock

func (l *LocalLock) Unlock(ctx context.Context) error

type PostgresFactory

type PostgresFactory struct{}

func NewPostgresFactory

func NewPostgresFactory() *PostgresFactory

func (*PostgresFactory) NewDistributedLock

func (f *PostgresFactory) NewDistributedLock(resource string, ttl time.Duration) DistributedLock

type RedisFactory

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

func NewRedisFactory

func NewRedisFactory(rds redis.Redis) *RedisFactory

func (*RedisFactory) NewDistributedLock

func (f *RedisFactory) NewDistributedLock(resource string, ttl time.Duration) DistributedLock

Jump to

Keyboard shortcuts

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