import ( "github.com/go-redis/redis/v7" "kgh/config" ) func ConnectRedis(db int) (*redis.Client, error) { var client *redis.Client //生成redis对象传入账号密码及那个数据库 client = redis.NewClient(&redis.Options{ Network: "tcp", Addr: config.InitConfig.Redis.Addr + ":" + config.InitConfig.Redis.Port, Password: config.InitConfig.Redis.Password, DB: db, PoolSize: config.InitConfig.Redis.PoolSize, MinIdleConns: config.InitConfig.Redis.MinIdleConns, }) _, err := client.Ping().Result() return client, err }