package init_serve import ( "context" "fmt" "github.com/go-redis/redis/v8" "hongze/hongze_yb_en_api/global" ) func Redis() { redisConf := global.CONFIG.Redis fmt.Println("redisConf.Address", redisConf.Address) fmt.Println("redisConf.Password", redisConf.Password) fmt.Println("redisConf.Db", redisConf.Db) client := redis.NewClient(&redis.Options{ Addr: redisConf.Address, Password: redisConf.Password, DB: redisConf.Db, //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置) }) _, err := client.Ping(context.TODO()).Result() fmt.Println("redis ping:", err) if err != nil { global.LOG.Error("redis 链接失败:", err) panic("redis 链接失败:" + err.Error()) } //全局赋值redis链接 global.Redis = client }