redis.go 525B

123456789101112131415161718192021
  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. client := redis.NewClient(&redis.Options{
  10. Addr: address,
  11. Password: beego.AppConfig.String("redispasswrod"), // no password set
  12. DB: 0, // use default DB
  13. })
  14. pong, err := client.Ping().Result()
  15. fmt.Println(pong, err)
  16. return client
  17. }