A simple but powerful distributed lock

nlock

A simple but powerful distributed lock

Get Started

Download

go get github.com/inuggets/nlock

Usage

Redis lock

import lock "github.com/inuggets/nlock"

redisPool := lock.NewRedisPool("localhost:6379", "PASSWORD")
key := "test"
l := lock.NewRedisLock(redisPool, 15) // ttl is 15s
if l.Lock(key) {
    defer l.Unlock(key)
    if l.HasLock(key) { // You can check if has lock
        ...
    }
    
    // Do something
    ...
}

Lock with waiting time

l := lock.NewRedisLock(redisPool, 15) // ttl is 15s
if lock.LockWait(key, 3) { // Wait up to 3s if key is locked but others
    defer l.Unlock(key)
}

Methods

- Lock(key string) bool                             // lock
- LockWait(key string, seconds int64) bool          // lock with waiting time
- Locked(key string) bool                           // check if locked
- HasLock(key string) bool                          // check if has/own lock
- Unlock(key string) bool                           // unlock

MySQL lock

import lock "github.com/inuggets/nlock"

db, _ := lock.NewMysqlClient("localhost:3306", "DB", "USER", "PASSWORD")
l := lock.NewMysqlLock(db, 15)
key := "test"
l := lock.NewRedisLock(redisPool, 15) // ttl is 15s
if l.Lock(key) {
    defer l.Unlock(key)
}

License

nlock is under the MIT license. See the LICENSE for detail.

Owner
Nuggets
If it's a rose, it will bloom sooner or later
Nuggets
Similar Resources

Fast, efficient, and scalable distributed map/reduce system, DAG execution, in memory or on disk, written in pure Go, runs standalone or distributedly.

Gleam Gleam is a high performance and efficient distributed execution system, and also simple, generic, flexible and easy to customize. Gleam is built

Jan 1, 2023

Go Micro is a framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Jan 8, 2023

Simplified distributed locking implementation using Redis

redislock Simplified distributed locking implementation using Redis. For more information, please see examples. Examples import ( "fmt" "time"

Dec 24, 2022

Skynet is a framework for distributed services in Go.

Skynet is a framework for distributed services in Go.

##Introduction Skynet is a communication protocol for building massively distributed apps in Go. It is not constrained to Go, so it will lend itself n

Nov 18, 2022

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Dapr is a portable, serverless, event-driven runtime that makes it easy for developers to build resilient, stateless and stateful microservices that run on the cloud and edge and embraces the diversity of languages and developer frameworks.

Jan 5, 2023

A distributed, proof of stake blockchain designed for the financial services industry.

Provenance Blockchain Provenance is a distributed, proof of stake blockchain designed for the financial services industry.

Dec 14, 2022

A distributed system for embedding-based retrieval

A distributed system for embedding-based retrieval

Overview Vearch is a scalable distributed system for efficient similarity search of deep learning vectors. Architecture Data Model space, documents, v

Dec 30, 2022

๐Ÿ’ก A Distributed and High-Performance Monitoring System. The next generation of Open-Falcon

๐Ÿ’ก A Distributed and High-Performance Monitoring System.  The next generation of Open-Falcon

ๅคœ่Žบ็ฎ€ไป‹ ๅคœ่Žบๆ˜ฏไธ€ๅฅ—ๅˆ†ๅธƒๅผ้ซ˜ๅฏ็”จ็š„่ฟ็ปด็›‘ๆŽง็ณป็ปŸ๏ผŒๆœ€ๅคง็š„็‰น็‚นๆ˜ฏๆททๅˆไบ‘ๆ”ฏๆŒ๏ผŒๆ—ขๅฏไปฅๆ”ฏๆŒไผ ็ปŸ็‰ฉ็†ๆœบ่™šๆ‹Ÿๆœบ็š„ๅœบๆ™ฏ๏ผŒไนŸๅฏไปฅๆ”ฏๆŒK8Sๅฎนๅ™จ็š„ๅœบๆ™ฏใ€‚ๅŒๆ—ถ๏ผŒๅคœ่ŽบไนŸไธๅชๆ˜ฏ็›‘ๆŽง๏ผŒ่ฟ˜ๆœ‰ไธ€้ƒจๅˆ†CMDB็š„่ƒฝๅŠ›ใ€่‡ชๅŠจๅŒ–่ฟ็ปด็š„่ƒฝๅŠ›๏ผŒๅพˆๅคšๅ…ฌๅธ้ƒฝๅŸบไบŽๅคœ่Žบๅผ€ๅ‘่‡ชๅทฑๅ…ฌๅธ็š„่ฟ็ปดๅนณๅฐใ€‚ๅผ€ๆบ็š„่ฟ™้ƒจๅˆ†ๅŠŸ่ƒฝๆจกๅ—ไนŸๆ˜ฏๅ•†ไธš็‰ˆๆœฌ็š„ไธ€้ƒจๅˆ†๏ผŒๆ‰€ไปฅๅฏ้ ๆ€งๆœ‰ไฟ

Jan 5, 2023
A distributed lock service in Go using etcd

locker A distributed lock service client for etcd. What? Why? A distributed lock service is somewhat self-explanatory. Locking (mutexes) as a service

Sep 27, 2022
Lockgate is a cross-platform locking library for Go with distributed locks using Kubernetes or lockgate HTTP lock server as well as the OS file locks support.

Lockgate Lockgate is a locking library for Go. Classical interface: 2 types of locks: shared and exclusive; 2 modes of locking: blocking and non-block

Dec 16, 2022
Distributed-Services - Distributed Systems with Golang to consequently build a fully-fletched distributed service

Distributed-Services This project is essentially a result of my attempt to under

Jun 1, 2022
Collection of high performance, thread-safe, lock-free go data structures

Garr - Go libs in a Jar Collection of high performance, thread-safe, lock-free go data structures. adder - Data structure to perform highly-performant

Dec 26, 2022
Distributed reliable key-value store for the most critical data of a distributed system

etcd Note: The main branch may be in an unstable or even broken state during development. For stable versions, see releases. etcd is a distributed rel

Dec 30, 2022
Go Open Source, Distributed, Simple and efficient Search Engine

Go Open Source, Distributed, Simple and efficient full text search engine.

Dec 31, 2022
Asynq: simple, reliable, and efficient distributed task queue in Go
Asynq: simple, reliable, and efficient distributed task queue in Go

Asynq: simple, reliable, and efficient distributed task queue in Go

Dec 31, 2022
distributed data sync with operational transformation/transforms

DOT The DOT project is a blend of operational transformation, CmRDT, persistent/immutable datastructures and reactive stream processing. This is an im

Dec 16, 2022
High performance, distributed and low latency publish-subscribe platform.
High performance, distributed and low latency publish-subscribe platform.

Emitter: Distributed Publish-Subscribe Platform Emitter is a distributed, scalable and fault-tolerant publish-subscribe platform built with MQTT proto

Jan 2, 2023