Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 738 Bytes

README.md

File metadata and controls

40 lines (34 loc) · 738 Bytes

nats-mutex

Nats-mutex is a distributed lock library using NATS.

Installation

go get github.com/jokruger/nats-mutex

Basic Usage

Process 1

...
m, _ := natsmutex.NewSyncMutex(
    natsmutex.WithUrl("nats://localhost:4222"),
    natsmutex.WithResourceID("123"),
)
m.Lock()
fmt.Println("Process 1 is in critical section")
time.Sleep(10 * time.Second)
m.Unlock()
...

Process 2

...
m, _ := natsmutex.NewSyncMutex(
    natsmutex.WithUrl("nats://localhost:4222"),
    natsmutex.WithResourceID("123"),
)
m.Lock()
fmt.Println("Process 2 is in critical section")
time.Sleep(10 * time.Second)
m.Unlock()
...

For more examples and betchmarks refer to https://github.com/jokruger/distributed-lock-benchmark