diff --git a/.env b/.env index 1e338da..40406ac 100644 --- a/.env +++ b/.env @@ -19,7 +19,6 @@ POSTGRES_PASSWORD=secret REDIS_HOST=redis REDIS_PORT=6379 REDIS_DB=2 -REDIS_URL="redis://${REDIS_HOST}:${REDIS_PORT}/${REDIS_DB}" JWT_EXPIRE=3600 JWT_ALGORITHM=HS256 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f9685a3..9553359 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -26,7 +26,6 @@ jobs: REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 REDIS_DB: 2 - REDIS_URL: redis://127.0.0.1:6379/2 JWT_EXPIRE: 3600 JWT_ALGORITHM: HS256 diff --git a/app/config.py b/app/config.py index 25d0c70..5afcc49 100644 --- a/app/config.py +++ b/app/config.py @@ -11,15 +11,44 @@ class Settings(BaseSettings): env_ignore_empty=True, extra="ignore" ) - redis_url: RedisDsn = os.getenv("REDIS_URL") jwt_algorithm: str = os.getenv("JWT_ALGORITHM") jwt_expire: int = os.getenv("JWT_EXPIRE") + REDIS_HOST: str + REDIS_PORT: int + REDIS_DB: str + + JWT_ALGORITHM: str + JWT_EXPIRE: int + SQL_USER: str SQL_PASS: str SQL_HOST: str SQL_DB: str + @computed_field + @property + def redis_url(self) -> RedisDsn: + """ + This is a computed field that generates a RedisDsn URL for redis-py. + + The URL is built using the MultiHostUrl.build method, which takes the following parameters: + - scheme: The scheme of the URL. In this case, it is "redis". + - host: The host of the Redis database, retrieved from the REDIS_HOST environment variable. + - port: The port of the Redis database, retrieved from the REDIS_PORT environment variable. + - path: The path of the Redis database, retrieved from the REDIS_DB environment variable. + + Returns: + RedisDsn: The constructed RedisDsn URL for redis-py. + """ + return MultiHostUrl.build( + scheme="redis", + host=self.REDIS_HOST, + port=self.REDIS_PORT, + path=self.REDIS_DB, + + ) + @computed_field @property def asyncpg_url(self) -> PostgresDsn: