MCPcopy
hub / github.com/go-redsync/redsync

github.com/go-redsync/redsync @v4.17.0 sqlite

repository ↗ · DeepWiki ↗ · release v4.17.0 ↗
190 symbols 536 edges 31 files 48 documented · 25%
README

Redsync

Go Reference Build Status

Redsync provides a Redis-based distributed mutual exclusion lock implementation for Go as described in this post. A reference library (by antirez) for Ruby is available at github.com/antirez/redlock-rb.

Installation

Install Redsync using the go get command:

$ go get github.com/go-redsync/redsync/v4

Two driver implementations will be installed; however, only the one used will be included in your project.

See the examples folder for usage of each driver.

Documentation

Usage

Error handling is simplified to panic for shorter example.

package main

import (
    goredislib "github.com/redis/go-redis/v9"
    "github.com/go-redsync/redsync/v4"
    "github.com/go-redsync/redsync/v4/redis/goredis/v9"
)

func main() {
    // Create a pool with go-redis (or redigo) which is the pool redsync will
    // use while communicating with Redis. This can also be any pool that
    // implements the `redis.Pool` interface.
    client := goredislib.NewClient(&goredislib.Options{
        Addr: "localhost:6379",
    })
    pool := goredis.NewPool(client) // or, pool := redigo.NewPool(...)

    // Create an instance of redsync to be used to obtain a mutual exclusion
    // lock.
    rs := redsync.New(pool)

    // Obtain a new mutex by using the same name for all instances wanting the
    // same lock.
    mutexname := "my-global-mutex"
    mutex := rs.NewMutex(mutexname)

    // Obtain a lock for our given mutex. After this is successful, no one else
    // can obtain the same lock (the same mutex name) until we unlock it.
    if err := mutex.Lock(); err != nil {
        panic(err)
    }

    // Do your work that requires the lock.

    // Release the lock so other processes or threads can obtain a lock.
    if ok, err := mutex.Unlock(); !ok || err != nil {
        panic("unlock failed")
    }
}

Contributing

Contributions are welcome.

License

Redsync is available under the BSD (3-Clause) License.

Disclaimer

This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in production environments.

Real World Uses

Below is a list of public, open source projects that use Redsync:

  • Sourcegraph: Universal code search and intelligence platform. Uses Redsync in an internal cache implementation.
  • Open Match by Google: Flexible, extensible, and scalable video game matchmaking. Uses Redsync with its state store implementation.
  • Gocron by go-co-op: gocron is a job distributed scheduling package which lets you run Go functions at pre-determined intervals using a simple, human-friendly syntax. Uses Redsync with its distributed job scheduler implementation.

If you are using Redsync in a project please send a pull request to add it to the list.

Extension points exported contracts — how you extend this code

Conn (Interface)
Conn is a single Redis connection. [7 implementers]
redis/redis.go
DelayFunc (FuncType)
A DelayFunc is used to decide the amount of time to wait between retries.
mutex.go
Option (Interface)
An Option configures a mutex.
redsync.go
Pool (Interface)
(no doc)
redis/redigo/redigo.go
Pool (Interface)
Pool maintains a pool of Redis connections.
redis/redis.go
OptionFunc (FuncType)
OptionFunc is a function that configures a mutex.
redsync.go

Core symbols most depended-on inside this repo

Lock
called by 17
mutex.go
Unlock
called by 13
mutex.go
NewMutex
called by 13
redsync.go
Get
called by 9
redis/redis.go
Eval
called by 8
redis/redis.go
Close
called by 8
redis/redis.go
Set
called by 7
redis/redis.go
SetNX
called by 7
redis/redis.go

Shape

Method 93
Function 68
Struct 23
Interface 4
FuncType 2

Languages

Go100%

Modules by API surface

mutex.go23 symbols
redsync.go19 symbols
mutex_test.go18 symbols
redis/redigo/redigo.go16 symbols
redis/valkeygo/valkeygo.go12 symbols
redis/rueidis/rueidis.go12 symbols
redis/redis.go12 symbols
redis/goredis/v9/goredis.go12 symbols
redis/goredis/v8/goredis.go12 symbols
redis/goredis/v7/goredis.go12 symbols
redis/goredis/goredis.go12 symbols
redsync_test.go11 symbols

Dependencies from manifests, versioned

github.com/cespare/xxhash/v2v2.3.0 · 1×
github.com/dgryski/go-rendezvousv0.0.0-2020082301473 · 1×
github.com/go-redis/redisv6.15.9+incompatible · 1×
github.com/go-redis/redis/v7v7.4.1 · 1×
github.com/go-redis/redis/v8v8.11.5 · 1×
github.com/gomodule/redigov1.9.3 · 1×
github.com/stvp/tempredisv0.0.0-2018111921243 · 1×
github.com/valkey-io/valkey-gov1.0.76 · 1×
github.com/valkey-io/valkey-go/valkeycompatv1.0.76 · 1×

For agents

$ claude mcp add redsync \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact