Documentation ¶
Index ¶
- Constants
- Variables
- func Get() *config
- type GoCacheLock
- type GoCacheLockProvider
- type Lock
- type LockFactory
- type Options
- type PROVIDER
- type RedisLock
- func (l *RedisLock) Key() string
- func (l *RedisLock) Lock(ctx context.Context) error
- func (l *RedisLock) Metadata() string
- func (l *RedisLock) Refresh(ctx context.Context, ttl time.Duration) error
- func (l *RedisLock) TTL(ctx context.Context) (time.Duration, error)
- func (l *RedisLock) TTLValueString() string
- func (l *RedisLock) Token() string
- func (l *RedisLock) UnLock(ctx context.Context) error
- func (l *RedisLock) WithOpt(opt *Options) Lock
- type RedisLockProvider
- type RetryStrategy
Constants ¶
View Source
const ( PROVIDER_REDIS = redis.AppName PROVIDER_GO_CACHE = gocache.AppName )
View Source
const (
AppName = "lock"
)
Variables ¶
View Source
var ( // ErrNotObtained is returned when a lock cannot be obtained. ErrNotObtained = errors.New("lock: not obtained") // ErrLockNotHeld is returned when trying to release an inactive lock. ErrLockNotHeld = errors.New("lock: lock not held") )
Functions ¶
Types ¶
type GoCacheLock ¶ added in v2.0.15
type GoCacheLock struct {
// contains filtered or unexported fields
}
func (*GoCacheLock) Lock ¶ added in v2.0.15
func (m *GoCacheLock) Lock(ctx context.Context) error
获取锁
type GoCacheLockProvider ¶ added in v2.0.15
type GoCacheLockProvider struct { }
func NewGoCacheLockProvider ¶ added in v2.0.15
func NewGoCacheLockProvider() *GoCacheLockProvider
type LockFactory ¶
func L ¶
func L() LockFactory
type Options ¶
type Options struct { // RetryStrategy allows to customise the lock retry strategy. // Default: do not retry RetryStrategy RetryStrategy // Metadata string. Metadata string // Token is a unique value that is used to identify the lock. By default, a random tokens are generated. Use this // option to provide a custom token instead. Token string }
Options describe the options for the lock
func DefaultOptions ¶
func DefaultOptions() *Options
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
Lock represents an obtained, distributed lock.
func (*RedisLock) TTLValueString ¶ added in v2.0.15
type RedisLockProvider ¶
type RedisLockProvider struct { }
func NewRedisLockProvider ¶
func NewRedisLockProvider() *RedisLockProvider
type RetryStrategy ¶
type RetryStrategy interface { // NextBackoff returns the next backoff duration. NextBackoff() time.Duration }
RetryStrategy allows to customise the lock retry strategy.
func ExponentialBackoff ¶
func ExponentialBackoff(min, max time.Duration) RetryStrategy
ExponentialBackoff strategy is an optimization strategy with a retry time of 2**n milliseconds (n means number of times). You can set a minimum and maximum value, the recommended minimum value is not less than 16ms.
func LimitRetry ¶
func LimitRetry(s RetryStrategy, max int) RetryStrategy
LimitRetry limits the number of retries to max attempts.
func LinearBackoff ¶
func LinearBackoff(backoff time.Duration) RetryStrategy
LinearBackoff allows retries regularly with customized intervals
Click to show internal directories.
Click to hide internal directories.