redis.go 498 B

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