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)
}

Etcd Lock

:lock:Distributed locks powered by etcd v3 for Go

Etcd Lock Info

⭐ Stars 13
🔗 Homepage godoc.org
🔗 Source Code github.com
🕒 Last Update 5 months ago
🕒 Created 5 years ago
🐞 Open Issues 0
➗ Star-Issue Ratio Infinity
😎 Author DavidCai1993