package service import ( "fmt" "github.com/astaxie/beego" "github.com/go-redis/redis" ) func RedisClient() *redis.Client { address := fmt.Sprintf("%s:%s", beego.AppConfig.String("redishost"), beego.AppConfig.String("redisport")) dbs, _ := beego.AppConfig.Int("redisdb") client := redis.NewClient(&redis.Options{ Addr: address, Password: beego.AppConfig.String("redispasswrod"), // no password set DB: dbs, // use default DB }) pong, err := client.Ping().Result() fmt.Println(pong, err) return client }