distributedlock

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 21 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 DistributedPostgresBunLock added in v0.7.0

type DistributedPostgresBunLock struct {
	BaseDistributedLock
}

func NewDistributedPostgresBunLock added in v0.7.0

func NewDistributedPostgresBunLock(resource string, ttl time.Duration) *DistributedPostgresBunLock

func (*DistributedPostgresBunLock) AutoExtend added in v0.7.0

func (*DistributedPostgresBunLock) Extend added in v0.7.0

func (*DistributedPostgresBunLock) Lock added in v0.7.0

func (*DistributedPostgresBunLock) TryLock added in v0.7.0

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

func (*DistributedPostgresBunLock) Unlock added in v0.7.0

type DistributedPostgresLock

type DistributedPostgresLock struct {
	BaseDistributedLock
}

func NewDistributedPostgresGORMLock added in v0.7.0

func NewDistributedPostgresGORMLock(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 PostgresBunFactory added in v0.7.0

type PostgresBunFactory struct{}

func NewPostgresBunFactory added in v0.7.0

func NewPostgresBunFactory() *PostgresBunFactory

func (*PostgresBunFactory) NewDistributedLock added in v0.7.0

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

type PostgresGORMFactory added in v0.7.0

type PostgresGORMFactory struct{}

func NewPostgresGORMFactory added in v0.7.0

func NewPostgresGORMFactory() *PostgresGORMFactory

func (*PostgresGORMFactory) NewDistributedLock added in v0.7.0

func (f *PostgresGORMFactory) 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
⌂ 换网址