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()
}

goper
413 声望26 粉丝

go 后端开发