Documentation
¶
Index ¶
Constants ¶
View Source
const TRY_INTERVAL time.Duration = 10 * time.Millisecond
Variables ¶
View Source
var LockFailed = errors.New("Lock failed")
Functions ¶
This section is empty.
Types ¶
type DistLock ¶
type DistLock interface { // Keep renew a lock held already for another {expire} time Keep(target interface{}) // Lock try to lock the specified resource in {wait} time or return a LockFailed error Lock(target interface{}, wait time.Duration) error TryLock(target interface{}) bool // UnLock releases the lock of specified resource id and return true for success UnLock(target interface{}) bool Close() }
func NewMutex ¶
NewMutex returns a non-reentry distributed lock
namespace is used to separate different projects expire indicates the expiration of an active lock and it will be removed if no {Keep} and {Unlock} was invoked during this. store decides which storage it uses
func NewReentry ¶
NewMutex returns a reentry distributed lock
namespace is used to separate different projects expire indicates the expiration of an active lock and it will be removed if no {Keep} and {Unlock} was invoked during this. store decides which storage it uses
type DistLockImpl ¶
type DistLockImpl struct {
// contains filtered or unexported fields
}
func (*DistLockImpl) Close ¶
func (l *DistLockImpl) Close()
func (*DistLockImpl) Keep ¶
func (l *DistLockImpl) Keep(target interface{})
func (*DistLockImpl) Lock ¶
func (l *DistLockImpl) Lock(target interface{}, wait time.Duration) error
func (*DistLockImpl) TryLock ¶
func (l *DistLockImpl) TryLock(target interface{}) bool
func (*DistLockImpl) UnLock ¶
func (l *DistLockImpl) UnLock(target interface{}) bool
type Store ¶
type Store interface { // Keep ensures the lock data in storage won't disappear during the period and update the content Keep(lockKey *LockKey, val string, expire time.Duration) // Exists return the existence of specified key Exists(lockKey *LockKey) bool Get(lockKey *LockKey) string SetIfAbsent(lockKey *LockKey, val string, expire time.Duration) bool Set(lockKey *LockKey, val string, expire time.Duration) Delete(lockKey *LockKey) Close() }
Click to show internal directories.
Click to hide internal directories.