redis.go 448 B

123456789101112131415161718192021222324
  1. package global
  2. import (
  3. "Panel_development/simple_zap"
  4. "context"
  5. "fmt"
  6. "github.com/go-redis/redis/v8"
  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. }