redis.go 591 B

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