Redis 中 分布式锁的使用
文章目录
github.com/cr-mao/goredislock package
package main
import (
"context"
"github.com/cr-mao/goredislock"
"github.com/go-redis/redis/v8"
"time"
)
//func GetMD5Hash(text string) string {
// hash := md5.Sum([]byte(text))
// return hex.EncodeToString(hash[:])
//}
//
//func GetSHA256(password string) string {
// hash := sha256.New()
// hash.Write([]byte(password))
// res := hex.EncodeToString(hash.Sum(nil))
// return res
//}
func main() {
RedisClient := redis.NewClient(&redis.Options{
Addr: "",
Username: "",
Password: "",
PoolSize: 10, // 连接池大小
})
locker, _ := goredislock.NewLocker("GetSeasonBusinessID",
goredislock.WithContext(context.Background()),
goredislock.WithExpire(time.Second*3), goredislock.WithRedisClient(RedisClient),
).Lock()
defer locker.Unlock()
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论