dlock:使用领事在Golang中进行分布式锁实现
dlock
使用领事在Golang中进行分布式锁实现
用法
锁初始化
d , err = dlock . New ( & dlock. Config { ConsulKey : "LockKV" , LockRetryInterval : time . Second * 10 })
if err != nil {
log . Println ( "Error " , err )
return
}
尝试获取锁
acquireCh := make ( chan bool )
releaseCh := make ( chan bool )
for { // loop is to re-attempt for lock acquisition when the lock was initially acquired but auto released after some time