golang distributed lock base on consul cluster
- create a session with TTL
- set key with sessionID and acquire
- session.Destroy()
go-consul-locker support call and event mode.
acquire lock direct
isLocked, err := d.TryLockAcquire(value)
event notify
acquireCh := make(chan bool)
releaseCh := make(chan bool)
errorCh := make(chan error)
d.RetryLockAcquire(value, acquireCh, releaseCh, errorCh)
select {
case <-acquireCh:
...
case err := <-errorCh:
log.Println(err.Error())
...
}
<-releaseCh
see example github.com/rfyiamcool/go-consul-locker/example