You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
649 B

3 years ago
  1. package initialize
  2. import (
  3. "context"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/go-redis/redis/v8"
  6. "go.uber.org/zap"
  7. )
  8. func Redis() {
  9. redisCfg := global.GVA_CONFIG.Redis
  10. client := redis.NewClient(&redis.Options{
  11. Addr: redisCfg.Addr,
  12. Password: redisCfg.Password, // no password set
  13. DB: redisCfg.DB, // use default DB
  14. })
  15. pong, err := client.Ping(context.Background()).Result()
  16. if err != nil {
  17. global.GVA_LOG.Error("redis connect ping failed, err:", zap.Error(err))
  18. } else {
  19. global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
  20. global.GVA_REDIS = client
  21. }
  22. }