redis.go 654 B

1234567891011121314151617181920212223242526
  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.Any("err", err))
  18. } else {
  19. global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
  20. global.GVA_REDIS = client
  21. }
  22. }