redis_config.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Configuration settings for Redis connection
  7. """
  8. REDIS_HOST: str = Field(
  9. description="Hostname or IP address of the Redis server",
  10. default="localhost",
  11. )
  12. REDIS_PORT: PositiveInt = Field(
  13. description="Port number on which the Redis server is listening",
  14. default=6379,
  15. )
  16. REDIS_USERNAME: Optional[str] = Field(
  17. description="Username for Redis authentication (if required)",
  18. default=None,
  19. )
  20. REDIS_PASSWORD: Optional[str] = Field(
  21. description="Password for Redis authentication (if required)",
  22. default=None,
  23. )
  24. REDIS_DB: NonNegativeInt = Field(
  25. description="Redis database number to use (0-15)",
  26. default=0,
  27. )
  28. REDIS_USE_SSL: bool = Field(
  29. description="Enable SSL/TLS for the Redis connection",
  30. default=False,
  31. )
  32. REDIS_USE_SENTINEL: Optional[bool] = Field(
  33. description="Enable Redis Sentinel mode for high availability",
  34. default=False,
  35. )
  36. REDIS_SENTINELS: Optional[str] = Field(
  37. description="Comma-separated list of Redis Sentinel nodes (host:port)",
  38. default=None,
  39. )
  40. REDIS_SENTINEL_SERVICE_NAME: Optional[str] = Field(
  41. description="Name of the Redis Sentinel service to monitor",
  42. default=None,
  43. )
  44. REDIS_SENTINEL_USERNAME: Optional[str] = Field(
  45. description="Username for Redis Sentinel authentication (if required)",
  46. default=None,
  47. )
  48. REDIS_SENTINEL_PASSWORD: Optional[str] = Field(
  49. description="Password for Redis Sentinel authentication (if required)",
  50. default=None,
  51. )
  52. REDIS_SENTINEL_SOCKET_TIMEOUT: Optional[PositiveFloat] = Field(
  53. description="Socket timeout in seconds for Redis Sentinel connections",
  54. default=0.1,
  55. )
  56. REDIS_USE_CLUSTERS: bool = Field(
  57. description="Enable Redis Clusters mode for high availability",
  58. default=False,
  59. )
  60. REDIS_CLUSTERS: Optional[str] = Field(
  61. description="Comma-separated list of Redis Clusters nodes (host:port)",
  62. default=None,
  63. )
  64. REDIS_CLUSTERS_PASSWORD: Optional[str] = Field(
  65. description="Password for Redis Clusters authentication (if required)",
  66. default=None,
  67. )