chore: 初始化仓库,排除二进制文件和覆盖率文件
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled
Test / test (push) Has been cancelled
Test / lint (push) Has been cancelled
Test / build (push) Has been cancelled

This commit is contained in:
lan
2025-11-28 23:30:49 +08:00
commit 4b4980820f
107 changed files with 20755 additions and 0 deletions

50
pkg/redis/manager.go Normal file
View File

@@ -0,0 +1,50 @@
package redis
import (
"carrotskin/pkg/config"
"fmt"
"sync"
"go.uber.org/zap"
)
var (
// clientInstance 全局Redis客户端实例
clientInstance *Client
// once 确保只初始化一次
once sync.Once
// initError 初始化错误
initError error
)
// Init 初始化Redis客户端线程安全只会执行一次
func Init(cfg config.RedisConfig, logger *zap.Logger) error {
once.Do(func() {
clientInstance, initError = New(cfg, logger)
if initError != nil {
return
}
})
return initError
}
// GetClient 获取Redis客户端实例线程安全
func GetClient() (*Client, error) {
if clientInstance == nil {
return nil, fmt.Errorf("Redis客户端未初始化请先调用 redis.Init()")
}
return clientInstance, nil
}
// MustGetClient 获取Redis客户端实例如果未初始化则panic
func MustGetClient() *Client {
client, err := GetClient()
if err != nil {
panic(err)
}
return client
}