Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. redis-lock

redis-lock

NOASSERTIONGo

A Go library providing a simplified distributed locking implementation using Redis.

GitHubGitHub
1.8k stars166 forks0 contributors

What is redis-lock?

redislock is a Go library that implements distributed locking using Redis as a backend. It solves the problem of coordinating access to shared resources across multiple processes or servers in a distributed system, preventing race conditions and ensuring mutual exclusion.

Target Audience

Go developers building distributed applications, microservices, or systems that require synchronization across multiple instances, such as job schedulers, resource managers, or critical section protectors.

Value Proposition

Developers choose redislock for its minimalistic and idiomatic Go API, reliability through Redis's persistence, and simplicity compared to rolling custom locking logic, making it a lightweight yet robust solution for distributed coordination.

Overview

Simplified distributed locking implementation using Redis

Use Cases

Best For

  • Implementing leader election in a cluster of Go services
  • Preventing duplicate processing of jobs in a distributed worker pool
  • Synchronizing access to shared external resources (e.g., databases, APIs)
  • Protecting critical sections in horizontally scaled applications
  • Ensuring only one instance runs a scheduled task at a time
  • Coordinating state changes across microservices in a transaction-like manner

Not Ideal For

  • Systems requiring reentrant locks or hierarchical locking structures
  • Applications where Redis network latency is a critical performance bottleneck
  • Projects needing out-of-the-box automatic retry with configurable backoff strategies
  • Environments without reliable Redis infrastructure or where Redis is a single point of failure

Pros & Cons

Pros

Simple Clean API

Offers intuitive functions like Obtain, Release, Refresh, and TTL, as shown in the example code, making integration straightforward without complex configuration.

Automatic Expiration Safety

Locks have a built-in TTL to prevent deadlocks from stale locks, and methods like TTL and Refresh allow for safe management in long-running operations.

Non-blocking Acquisition

The Obtain method returns immediately with an error if the lock is unavailable, enabling efficient error handling without blocking, as demonstrated in the example.

Cons

No Built-in Retry Logic

Default acquisition has zero backoff retries, requiring developers to manually implement retry loops, as indicated in the example where ErrNotObtained leads to immediate return.

Redis Dependency Risks

Locks rely entirely on Redis availability; any downtime or network issues can cause lock failures, making the system vulnerable without additional fault tolerance.

Limited Advanced Features

Focuses on simplicity, so it lacks support for reentrant locks, fair locking, or multi-master Redis setups, which might be necessary for complex distributed systems.

Frequently Asked Questions

Quick Stats

Stars1,766
Forks166
Contributors0
Open Issues2
Last commit27 days ago
CreatedSince 2019

Tags

#go-redis#lock#coordination#distributed#redis#distributed-systems#go-library#distributed-locking#golang#concurrency#distributed-lock

Built With

G
Go
R
Redis

Included in

Go169.1k
Auto-fetched 18 hours ago

Related Projects

Go-zeroGo-zero

A cloud-native Go microservices framework with cli tool for productivity.

Stars33,213
Forks4,312
Last commit1 day ago
go-kitgo-kit

A standard library for microservices.

Stars27,431
Forks2,444
Last commit2 years ago
KratosKratos

Your ultimate Go microservices framework for the cloud-native era.

Stars25,803
Forks4,168
Last commit23 days ago
grpc-gogrpc-go

The Go language implementation of gRPC. HTTP/2 based RPC

Stars23,013
Forks4,725
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub