Skip to content

DavidCai1111/etcd-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

etcd-lock

Build Status Coverage Status

Distributed locks powered by etcd v3 for Go.

Installation

go get -u github.com/DavidCai1993/etcd-lock

Documentation

API documentation can be found here: https://godoc.org/github.com/DavidCai1993/etcd-lock

Usage

import (
  "github.com/DavidCai1993/etcd-lock"
)
locker, err := etcdlock.NewLocker(etcdlock.LockerOptions{
  Address:        "127.0.0.1:2379",
  DialOptions:    []grpc.DialOption{grpc.WithInsecure()},
})

if err != nil {
  log.Fatalln(err)
}

// Acquire a lock for a specified recource.
if _, err = locker.Lock(context.Background(), "resource_key", 5*time.Second); err != nil {
  log.Fatalln(err)
}

// This lock will be acquired after 5s, and before that current goroutine
// will be blocked.
anotherLock, err := locker.Lock(context.Background(), "resource_key", 5*time.Second)
if err != nil {
  log.Fatalln(err)
}

// Unlock the lock manually.
if err := anotherLock.Unlock(context.Background()); err != nil {
  log.Fatalln(err)
}

About

🔒Distributed locks powered by etcd v3 for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published