Skip to content
kisara71Public

About

A simple Redis-based distributed lock implemented in Go.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gorlock

A lightweight distributed lock library based on Redis for Go.
一个基于 Redis 的轻量级 Go 分布式锁库。


Usage / 使用示例

rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
client := gorlock.NewClient(rdb)

ctx := context.Background()
lock, err := client.Lock(ctx, "my-lock", 10*time.Second)
if err != nil {
    log.Fatal("failed to acquire lock:", err)
}
defer lock.Unlock(ctx)

Retry Customization / 自定义重试策略

You can provide a custom retry strategy by implementing the RetryStrategy interface and passing it via WithRetryStrategy.

你可以实现 RetryStrategy 接口,并通过 WithRetryStrategy 参数传入来自定义重试逻辑。

type myRetry struct{}
func (r *myRetry) Next() (time.Duration, bool) {
    return time.Second, true // retry every 1 second
}

lock, err := client.Lock(
    ctx,
    "my-lock",
    10*time.Second,
    gorlock.WithRetryStrategy(&myRetry{}),
)

About

A simple Redis-based distributed lock implemented in Go.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages