Disgo - A distributed lock based on redis developed with golang

English | 中文

DisGo Introduce

DisGo is a distributed lock based on Redis, developed in Golang language. The name comes from Distributed, Disco and Golang, I wish you all to write code as easy as dancing disco.

Features of DisGo

Reentrant Lock

DisGo is a reentrant lock. It uses the Redis's Hash type as the lock, the hash-name is the lock name, the hash-key stores the unique id of the current lock-holding thread, and the hash-value stores the current number of locks.

Fair Lock

Golang itself does not have thread-safe queues to use. For convenience, DisGo uses Redis's ZSet to simulate queues, which ensures first-in first-out(FIFO) to a certain extent and provides a fair lock.

Auto-Renew

DisGo provides an automatic renewal function to prevent data errors caused by early release of locks before business execution is completed.

Spin Lock

DisGo is a spin lock, which will automatically retry the lock grab within the set waiting time until the lock is grabbed or the wait times out.

More Efficient

DisGo uses Redis's publish and subscribe, and will receive the message as soon as the lock is released, and then execute the lock according to the order of the waiting queue.

DisGo locking process

Click Me

API Introduction

Acquire lock object

    redisClient := redis.NewClient(&redis.Options{
        Network: "tcp",
        Addr:    "127.0.0.1:6379",
    })
    lock := disgo.GetLock(redisClient, "test")

Ordinary lock (no spin lock and automatic renewal required)

    success, err := lock.Lock(ctx, 5*time.Second, 10*time.Second)

Spin lock (no auto-renewal required)

    success, err := lock.TryLock(ctx, 5*time.Second, 10*time.Second)

Spin lock (auto-renew)

    success, err := lock.TryLockWithSchedule(ctx, 5*time.Second)

Unlock (Universal)

    success, err := lock.Release(ctx)
Similar Resources

A distributed key-value store. On Disk. Able to grow or shrink without service interruption.

Vasto A distributed high-performance key-value store. On Disk. Eventual consistent. HA. Able to grow or shrink without service interruption. Vasto sca

Jan 6, 2023

A distributed Configuration Center server that manages config in a container. The container is composed of fields (abstract layer includes: KV, LIST, DICT type). The Field contains basic datatypes (int, float, bool, string, list, dict).

A distributed Configuration Center server that manages config in a container. The container is composed of fields (abstract layer includes: KV, LIST, DICT type). The Field contains basic datatypes (int, float, bool, string, list, dict).

cassem config assembler from key-value pairs' container which include basic datatypes, such as int, string, float, bool, list, dict Features HTTP Rest

Nov 1, 2022

A distributed MySQL binlog storage system built on Raft

A distributed MySQL binlog storage system built on Raft

What is kingbus? 中文 Kingbus is a distributed MySQL binlog store based on raft. Kingbus can act as a slave to the real master and as a master to the sl

Dec 31, 2022

Distributed cache with gossip peer membership enrollment.

Autocache Groupcache enhanced with memberlist for distributed peer discovery. TL;DR See /_example/ for usage. Run docker-compose -f _example/docker-co

Dec 8, 2022

LBADD: An experimental, distributed SQL database

LBADD: An experimental, distributed SQL database

LBADD Let's build a distributed database. LBADD is an experimental distributed SQL database, written in Go. The goal of this project is to build a dat

Nov 29, 2022

A course to build the SQL layer of a distributed database.

TinySQL TinySQL is a course designed to teach you how to implement a distributed relational database in Go. TinySQL is also the name of the simplifed

Jan 8, 2023

TalariaDB is a distributed, highly available, and low latency time-series database for Presto

TalariaDB is a distributed, highly available, and low latency time-series database for Presto

TalariaDB is a distributed, highly available, and low latency time-series database that stores real-time data. It's built on top of Badger DB.

Nov 16, 2022

Distributed RWMutex in Go

Distributed RWMutex in Go

Distributed Read-Write Mutex in Go The default Go implementation of sync.RWMutex does not scale well to multiple cores, as all readers contend on the

Dec 29, 2022

Redwood is a highly-configurable, distributed, realtime database that manages a state tree shared among many peers

Redwood is a highly-configurable, distributed, realtime database that manages a state tree shared among many peers. Imagine something like a Redux store, but distributed across all users of an application, that offers offline editing and is resilient to poor connectivity.

Jan 8, 2023
Comments
  • 提个bug

    提个bug

    请您review一下您的代码是否存在下面的问题呢?

    在cas方法中,ttl, err := dl.tryAcquire(deadlinectx, dl.distLock.lockKey, dl.distLock.field, expiryTime, isNeedScheduled),您传的是deadlinectx,当cas获取到锁的时候,锁就会遵循deadlinectx的过期时间,到了时间,锁就会被释放了。

Related tags
High-performance Redis-Server multi-threaded framework, based on rawepoll model.
High-performance Redis-Server multi-threaded framework, based on rawepoll model.

RedHub High-performance Redis-Server multi-threaded framework, based on RawEpoll model. Ultra high performance Fully multi-threaded support Low CPU re

Dec 18, 2022
IceFireDB - Distributed disk storage system based on Raft and RESP protocol.
IceFireDB - Distributed disk storage system based on Raft and RESP protocol.

Distributed disk storage database based on Raft and Redis protocol.

Dec 27, 2022
MyCache - A distributed cache based on GeeCache

借鉴GeeCache实现了MyCache(https://geektutu.com/post/geecache.html) 主要功能: 1.实现了fifo和lr

Feb 18, 2022
Redis compatible server framework for Go
Redis compatible server framework for Go

Redis compatible server framework for Go Features Create a Fast custom Redis compatible server in Go Simple interface. One function ListenAndServe and

Dec 28, 2022
redic - Bindings for hiredis Redis-client library

This repo is a fork of https://github.com/redis/hiredis. redic - Bindings for hiredis Redis-client Go library Install go get -u github.com/hjyoun0731/

Dec 21, 2021
Virsas-mod-db - Quick way to init mysql, postgres and redis connection from multiple services without duplicating the code

Quick way to init mysql, postgres and redis connection from multiple services without duplicating the code.

Jan 23, 2022
Eventually consistent distributed in-memory cache Go library

bcache A Go Library to create distributed in-memory cache inside your app. Features LRU cache with configurable maximum keys Eventual Consistency sync

Dec 2, 2022
CockroachDB - the open source, cloud-native distributed SQL database.
CockroachDB - the open source, cloud-native distributed SQL database.

CockroachDB is a cloud-native SQL database for building global, scalable cloud services that survive disasters. What is CockroachDB? Docs Quickstart C

Jan 2, 2023
The lightweight, distributed relational database built on SQLite.
The lightweight, distributed relational database built on SQLite.

rqlite is a lightweight, distributed relational database, which uses SQLite as its storage engine. Forming a cluster is very straightforward, it grace

Jan 5, 2023
TiDB is an open source distributed HTAP database compatible with the MySQL protocol
TiDB is an open source distributed HTAP database compatible with the MySQL protocol

Slack Channel Twitter: @PingCAP Reddit Mailing list: lists.tidb.io For support, please contact PingCAP What is TiDB? TiDB ("Ti" stands for Titanium) i

Jan 9, 2023