dlock

package
v0.0.0-...-c23f155 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EtcdDLockBuilder

func EtcdDLockBuilder(ctx context.Context, client *clientv3.Client) *etcdDLockOptions

func RedisDLockBuilder

func RedisDLockBuilder(ctx context.Context, scripter func() redis.Scripter) *redisDLockOptions

Types

type DLockErr

type DLockErr string
const (
	ErrDLockAcquireFailed DLockErr = "failed to acquire dlock"
	ErrDLockNoInit        DLockErr = "no init the dlock"
)

func (DLockErr) Error

func (err DLockErr) Error() string

type DLocker

type DLocker interface {
	Lock() error
	Unlock() error
	Renewal(newTTL time.Duration) error
	TTL() (time.Duration, error)
}

func EtcdDLock

func EtcdDLock(ctx context.Context, client *clientv3.Client, opts ...EtcdDLockOption) (DLocker, error)

func RedisDLock

func RedisDLock(ctx context.Context, scripter func() redis.Scripter, opts ...RedisDLockOption) (DLocker, error)

type EtcdDLockOption

type EtcdDLockOption func(opt *etcdDLockOptions)

func WithEtcdDLockKeys

func WithEtcdDLockKeys(keys ...string) EtcdDLockOption

func WithEtcdDLockRetry

func WithEtcdDLockRetry(strategy RetryStrategy) EtcdDLockOption

func WithEtcdDLockTTL

func WithEtcdDLockTTL(ttl time.Duration) EtcdDLockOption

type RedisDLockOption

type RedisDLockOption func(opt *redisDLockOptions)

func WithRedisDLockKeys

func WithRedisDLockKeys(keys ...string) RedisDLockOption

func WithRedisDLockRetry

func WithRedisDLockRetry(strategy RetryStrategy) RedisDLockOption

func WithRedisDLockTTL

func WithRedisDLockTTL(ttl time.Duration) RedisDLockOption

func WithRedisDLockToken

func WithRedisDLockToken(token string) RedisDLockOption

type RetryStrategy

type RetryStrategy interface {
	Next() time.Duration
}

func DefaultExponentialBackoffRetry

func DefaultExponentialBackoffRetry() RetryStrategy

func EndlessRetry

func EndlessRetry(backoff time.Duration) RetryStrategy

func ExponentialBackoffRetry

func ExponentialBackoffRetry(maxSteps int64, initBackoff, maxBackoff time.Duration, backoffFactor, jitter float64) RetryStrategy

func LimitedRetry

func LimitedRetry(backoff time.Duration, maxCount int64) RetryStrategy

func NoRetry

func NoRetry() RetryStrategy

Jump to

Keyboard shortcuts

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