1234567891011121314151617181920212223242526272829 |
- package infra
- import (
- "github.com/go-redis/redis"
- "sync"
- )
- var (
- once sync.Once
- GlobalRedisClient *redis.Client
- )
- func InitRedisClient(addr string, password string, db int) {
- once.Do(func() {
-
- GlobalRedisClient = redis.NewClient(&redis.Options{
- Addr: addr,
- Password: password,
- DB: db,
- })
- })
-
- _, err := GlobalRedisClient.Ping().Result()
- if err != nil {
- GlobalLogger.Error("初始化 Redis 客户端报错:", err)
- }
- GlobalLogger.Error("初始化 Redis 客户端成功。")
- }
|