This commit is contained in:
2026-03-13 15:51:59 +08:00
parent 4db2386bbf
commit 4e91f4cede
133 changed files with 19502 additions and 37 deletions

View File

@@ -0,0 +1,26 @@
package config
import (
"context"
"fmt"
"log/slog"
"github.com/go-redis/redis/v8"
)
// NewRedis 初始化 Redis 客户端
func NewRedis(cfg RedisConfig) (*redis.Client, error) {
rdb := redis.NewClient(&redis.Options{
Addr: cfg.Addr,
Password: cfg.Password,
DB: cfg.DB,
PoolSize: cfg.PoolSize,
})
if err := rdb.Ping(context.Background()).Err(); err != nil {
return nil, fmt.Errorf("ping redis: %w", err)
}
slog.Info("redis connected")
return rdb, nil
}