redis.go 617 B

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