redis.go 449 B

123456789101112131415161718192021222324
  1. package global
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/go-redis/redis/v8"
  6. "project_management/simple_zap"
  7. )
  8. var Rdb *redis.Client
  9. func SetupRedisLink() {
  10. Rdb = redis.NewClient(&redis.Options{
  11. Addr: RedisSetting.Addr,
  12. Password: "",
  13. DB: 0,
  14. })
  15. ctx := context.Background()
  16. _, err := Rdb.Ping(ctx).Result()
  17. if err != nil {
  18. simple_zap.WithCtx(context.Background()).Sugar().Warn("redis连接失败", err)
  19. fmt.Println(err)
  20. }
  21. }