redis_config.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from typing import Optional
  2. from pydantic import Field, NonNegativeInt, PositiveFloat, PositiveInt
  3. from pydantic_settings import BaseSettings
  4. class RedisConfig(BaseSettings):
  5. """
  6. Redis configs
  7. """
  8. REDIS_HOST: str = Field(
  9. description="Redis host",
  10. default="localhost",
  11. )
  12. REDIS_PORT: PositiveInt = Field(
  13. description="Redis port",
  14. default=6379,
  15. )
  16. REDIS_USERNAME: Optional[str] = Field(
  17. description="Redis username",
  18. default=None,
  19. )
  20. REDIS_PASSWORD: Optional[str] = Field(
  21. description="Redis password",
  22. default=None,
  23. )
  24. REDIS_DB: NonNegativeInt = Field(
  25. description="Redis database id, default to 0",
  26. default=0,
  27. )
  28. REDIS_USE_SSL: bool = Field(
  29. description="whether to use SSL for Redis connection",
  30. default=False,
  31. )
  32. REDIS_USE_SENTINEL: Optional[bool] = Field(
  33. description="Whether to use Redis Sentinel mode",
  34. default=False,
  35. )
  36. REDIS_SENTINELS: Optional[str] = Field(
  37. description="Redis Sentinel nodes",
  38. default=None,
  39. )
  40. REDIS_SENTINEL_SERVICE_NAME: Optional[str] = Field(
  41. description="Redis Sentinel service name",
  42. default=None,
  43. )
  44. REDIS_SENTINEL_USERNAME: Optional[str] = Field(
  45. description="Redis Sentinel username",
  46. default=None,
  47. )
  48. REDIS_SENTINEL_PASSWORD: Optional[str] = Field(
  49. description="Redis Sentinel password",
  50. default=None,
  51. )
  52. REDIS_SENTINEL_SOCKET_TIMEOUT: Optional[PositiveFloat] = Field(
  53. description="Redis Sentinel socket timeout",
  54. default=0.1,
  55. )