Skip to content

rfyiamcool/go-consul-locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-consul-locker

golang distributed lock base on consul cluster

Lock Idea

acquire

  1. create a session with TTL
  2. set key with sessionID and acquire

release

  1. session.Destroy()

Desc

go-consul-locker support call and event mode.

call mode:

acquire lock direct

isLocked, err := d.TryLockAcquire(value)

event mode:

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

Usage

see example github.com/rfyiamcool/go-consul-locker/example

About

golang distributed lock base on consul cluster

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages