Documentation ¶
Index ¶
- Variables
- type BaseDistributedLock
- type DistributedLock
- type DistributedPostgresLock
- func (l *DistributedPostgresLock) AutoExtend(ctx context.Context) (context.Context, error)
- func (l *DistributedPostgresLock) Extend(ctx context.Context) (bool, error)
- func (l *DistributedPostgresLock) Lock(ctx context.Context) error
- func (l *DistributedPostgresLock) TryLock(ctx context.Context) (locked bool, err error)
- func (l *DistributedPostgresLock) Unlock(ctx context.Context) error
- type DistributedRedisLock
- func (l *DistributedRedisLock) AutoExtend(ctx context.Context) (context.Context, error)
- func (l *DistributedRedisLock) Extend(ctx context.Context) (bool, error)
- func (l *DistributedRedisLock) Lock(ctx context.Context) error
- func (l *DistributedRedisLock) TryLock(ctx context.Context) (bool, error)
- func (l *DistributedRedisLock) Unlock(ctx context.Context) error
- type Factory
- type LocalFactory
- type LocalLock
- func (l *LocalLock) AutoExtend(ctx context.Context) (context.Context, error)
- func (l *LocalLock) Extend(ctx context.Context) (bool, error)
- func (l *LocalLock) Lock(ctx context.Context) error
- func (l *LocalLock) TryLock(ctx context.Context) (bool, error)
- func (l *LocalLock) Unlock(ctx context.Context) error
- type PostgresFactory
- type RedisFactory
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCodeLockNotAutoExtended = "LOCK_NOT_AUTO_EXTENDED"
View Source
var ModuleLocal = di.FxProvideAs[Factory](NewLocalFactory, nil, nil)
View Source
var ModulePostgres = di.FxProvideAs[Factory](NewPostgresFactory, nil, nil)
View Source
var ModuleRedis = di.FxProvideAs[Factory](NewRedisFactory, nil, nil)
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 (l *DistributedPostgresLock) Lock(ctx context.Context) error
type DistributedRedisLock ¶
type DistributedRedisLock struct { BaseDistributedLock // contains filtered or unexported fields }
func NewDistributedRedisLock ¶
func (*DistributedRedisLock) AutoExtend ¶
func (*DistributedRedisLock) Extend ¶
func (l *DistributedRedisLock) Extend(ctx context.Context) (bool, error)
func (*DistributedRedisLock) Lock ¶
func (l *DistributedRedisLock) Lock(ctx context.Context) error
Lock will block until the lock is acquired or an error occurs.
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 (*LocalLock) AutoExtend ¶
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
Click to show internal directories.
Click to hide internal directories.