Ai
1 Star 0 Fork 0

青榄/goadmincore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
redis.go 551 Bytes
一键复制 编辑 原始数据 按行查看 历史
wangxinghong 提交于 2021-10-05 16:51 +08:00 . 新建
package locker
import (
"time"
"github.com/bsm/redislock"
"github.com/go-redis/redis/v7"
)
// 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(key, time.Duration(ttl)*time.Second, options)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qlanwl/goadmincore.git
git@gitee.com:qlanwl/goadmincore.git
qlanwl
goadmincore
goadmincore
e99d2202423a

搜索帮助