Documentation ¶
Index ¶
Constants ¶
View Source
const ( // DefaultDuration is the default duration of the lock DefaultDuration = 10 * time.Second // DefaultAttempts is the default attempts for acquiring lock DefaultAttempts = 7 // DefaultDelay is the default delay between attempts DefaultDelay = 512 * time.Millisecond // DefaultFactor is the default drift factor DefaultFactor = 0.01 )
Variables ¶
View Source
var ( // ErrLockFailedAfterMaxAttempts is the error for failing to acquire the lock after maximum attempts ErrLockFailedAfterMaxAttempts = errors.New("Lock Error: fail to acquire lock after maximum attempts!") // ErrLockExtensionFailed is the error for failing to extend the lock ErrLockExtensionFailed = errors.New("Lock Error: lock extension failed!") // ErrLockLost is the error for lock lost during auto renewal ErrLockLost = errors.New("Lock Error: lock is lost during auto renewal!") )
View Source
var ( // LockARCommandStop is the command for stopping the auto renew timer LockARCommandStop = "STOP" // LockARSignalStopSuccess is the signal for a successful stop LockARSignalStopSuccess = "STOPSuccess" )
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct { Key string // redis key Duration time.Duration // duration of the lock Factor float64 // drif factor MaxAttempts int // maxmium attempts to acquire the lock before failure Delay time.Duration // delay between attempts AutoRenew bool // whether to auto renew the lock Client *redis.Pool // the redis client ARControl chan string // auto renew control channel ARResult chan string // auto renew result channel // contains filtered or unexported fields }
Lock is a lock on a key
func NewLockOnKey ¶
NewLockOnKey creates a lock struct (unacquired) on a key
Click to show internal directories.
Click to hide internal directories.