Skip to content

Commit 3b98c21

Browse files
authored
Merge pull request #140 from grillazz/refactor
Refactor
2 parents 3a4367e + f7abc9f commit 3b98c21

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

.env

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SQL_TEST_DB=testdb
66
SQL_HOST=db
77
SQL_USER=user
88
SQL_PASS=secret
9-
#SQL_URL=postgresql+asyncpg://${SQL_USER}:${SQL_PASS}@${SQL_HOST}/${SQL_DB}
109

1110
# Postgres
1211
POSTGRES_SERVER=db
@@ -20,7 +19,6 @@ POSTGRES_PASSWORD=secret
2019
REDIS_HOST=redis
2120
REDIS_PORT=6379
2221
REDIS_DB=2
23-
REDIS_URL="redis://${REDIS_HOST}:${REDIS_PORT}/${REDIS_DB}"
2422

2523
JWT_EXPIRE=3600
2624
JWT_ALGORITHM=HS256

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ jobs:
2323
SQL_USER: app-user
2424
POSTGRES_PASSWORD: secret
2525
PGPASSWORD: secret
26-
# SQL_URL: postgresql+asyncpg://app-user:secret@localhost:5432/testdb
2726
REDIS_HOST: 127.0.0.1
2827
REDIS_PORT: 6379
2928
REDIS_DB: 2
30-
REDIS_URL: redis://127.0.0.1:6379/2
3129
JWT_EXPIRE: 3600
3230
JWT_ALGORITHM: HS256
3331

app/config.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,44 @@ class Settings(BaseSettings):
1111
env_ignore_empty=True,
1212
extra="ignore"
1313
)
14-
redis_url: RedisDsn = os.getenv("REDIS_URL")
1514
jwt_algorithm: str = os.getenv("JWT_ALGORITHM")
1615
jwt_expire: int = os.getenv("JWT_EXPIRE")
1716

17+
REDIS_HOST: str
18+
REDIS_PORT: int
19+
REDIS_DB: str
20+
21+
JWT_ALGORITHM: str
22+
JWT_EXPIRE: int
23+
1824
SQL_USER: str
1925
SQL_PASS: str
2026
SQL_HOST: str
2127
SQL_DB: str
2228

29+
@computed_field
30+
@property
31+
def redis_url(self) -> RedisDsn:
32+
"""
33+
This is a computed field that generates a RedisDsn URL for redis-py.
34+
35+
The URL is built using the MultiHostUrl.build method, which takes the following parameters:
36+
- scheme: The scheme of the URL. In this case, it is "redis".
37+
- host: The host of the Redis database, retrieved from the REDIS_HOST environment variable.
38+
- port: The port of the Redis database, retrieved from the REDIS_PORT environment variable.
39+
- path: The path of the Redis database, retrieved from the REDIS_DB environment variable.
40+
41+
Returns:
42+
RedisDsn: The constructed RedisDsn URL for redis-py.
43+
"""
44+
return MultiHostUrl.build(
45+
scheme="redis",
46+
host=self.REDIS_HOST,
47+
port=self.REDIS_PORT,
48+
path=self.REDIS_DB,
49+
50+
)
51+
2352
@computed_field
2453
@property
2554
def asyncpg_url(self) -> PostgresDsn:

0 commit comments

Comments
 (0)