redis.go 567B

12345678910111213141516171819202122
  1. package service
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego"
  5. "github.com/go-redis/redis"
  6. )
  7. func RedisClient() *redis.Client {
  8. address := fmt.Sprintf("%s:%s", beego.AppConfig.String("redishost"), beego.AppConfig.String("redisport"))
  9. dbs, _ := beego.AppConfig.Int("redisdb")
  10. client := redis.NewClient(&redis.Options{
  11. Addr: address,
  12. Password: beego.AppConfig.String("redispasswrod"), // no password set
  13. DB: dbs, // use default DB
  14. })
  15. pong, err := client.Ping().Result()
  16. fmt.Println(pong, err)
  17. return client
  18. }