1 Star 0 Fork 0

linxing/youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redis.go 578 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2023-12-23 11:58 . init
package locker
import (
"context"
"github.com/go-redis/redis/v9"
"time"
"github.com/bsm/redislock"
)
// NewRedis 初始化locker
func NewRedis(c *redis.Client) *Redis {
return &Redis{
client: c,
}
}
type Redis struct {
client *redis.Client
mutex *redislock.Client
}
func (Redis) String() string {
return "redis"
}
func (r *Redis) Lock(key string, ttl int64, options *redislock.Options) (*redislock.Lock, error) {
if r.mutex == nil {
r.mutex = redislock.New(r.client)
}
return r.mutex.Obtain(context.TODO(), key, time.Duration(ttl)*time.Second, options)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202403210935

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385