activecheck

package
v0.0.0-...-8cc84bd Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetryCount is the max retry times for lock acquire
	DefaultRetryCount = 10

	// DefaultRetryDelay is upper wait time in millisecond for lock acquire retry
	DefaultRetryDelay = 200

	// ClockDriftFactor is clock drift factor, more information refers to doc
	ClockDriftFactor = 0.01

	// UnlockScript is redis lua script to release a lock
	UnlockScript = `` /* 155-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveChecker

type ActiveChecker interface {
	// Start access to slice of Redis hosts, trying to set lock during provided period using Redlock algorithm
	Start(RedLocker, time.Duration) (bool, error)
	IsActive() bool
	SetActive()
	SetPassive()
	// Keepalive for active instance updates lock's expiration
	Keepalive() error

	GetValue() string
}

ActiveChecker trying to lock active mode on Start(), then Keepalive() lock while active

func NewActiveCheck

func NewActiveCheck(lockKey string) ActiveChecker

NewActiveCheck instantiates ActiveChecker

type AddressListFlags

type AddressListFlags []string

func (*AddressListFlags) Set

func (alf *AddressListFlags) Set(s string) error

func (*AddressListFlags) String

func (alf *AddressListFlags) String() string

type RedClient

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

RedClient holds client to redis

type RedLock

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

RedLock holds the redis lock

func (*RedLock) ExpireLock

func (r *RedLock) ExpireLock(resource, val string, ttl int64) (int64, error)

ExpireLock changes distributed lock expiration

func (*RedLock) Lock

func (r *RedLock) Lock(resource string, ttl int64) (string, error)

Lock acquires a distribute lock

func (*RedLock) SetRetryCount

func (r *RedLock) SetRetryCount(count int)

SetRetryCount sets acquire lock retry count

func (*RedLock) SetRetryDelay

func (r *RedLock) SetRetryDelay(delay int)

SetRetryDelay sets acquire lock retry max internal in millisecond

func (*RedLock) UnLock

func (r *RedLock) UnLock(resource, val string)

UnLock releases an acquired lock

type RedLocker

type RedLocker interface {
	// Lock acquires lock for specified resource and period in ms, returns assigned value
	Lock(resource string, period int64) (string, error)
	// ExpireLock changes expiration for resource with value to new period in ms, returns remained period
	ExpireLock(resource, value string, period int64) (int64, error)
	// SetRetryCount updates acquire lock attempts count
	SetRetryCount(int)
	// SetRetryDelay updates retry delays in milliseconds between acquire lock attempts
	SetRetryDelay(int)
}

RedLocker interface to implement Reddlock

func NewRedLock

func NewRedLock(addrs []string) (RedLocker, error)

NewRedLock creates a RedLock

Jump to

Keyboard shortcuts

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