File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ SQL_TEST_DB=testdb
6
6
SQL_HOST = db
7
7
SQL_USER = user
8
8
SQL_PASS = secret
9
- # SQL_URL=postgresql+asyncpg://${SQL_USER}:${SQL_PASS}@${SQL_HOST}/${SQL_DB}
10
9
11
10
# Postgres
12
11
POSTGRES_SERVER = db
@@ -20,7 +19,6 @@ POSTGRES_PASSWORD=secret
20
19
REDIS_HOST = redis
21
20
REDIS_PORT = 6379
22
21
REDIS_DB = 2
23
- REDIS_URL = " redis://${ REDIS_HOST } :${ REDIS_PORT } /${ REDIS_DB } "
24
22
25
23
JWT_EXPIRE = 3600
26
24
JWT_ALGORITHM = HS256
Original file line number Diff line number Diff line change 23
23
SQL_USER : app-user
24
24
POSTGRES_PASSWORD : secret
25
25
PGPASSWORD : secret
26
- # SQL_URL: postgresql+asyncpg://app-user:secret@localhost:5432/testdb
27
26
REDIS_HOST : 127.0.0.1
28
27
REDIS_PORT : 6379
29
28
REDIS_DB : 2
30
- REDIS_URL : redis://127.0.0.1:6379/2
31
29
JWT_EXPIRE : 3600
32
30
JWT_ALGORITHM : HS256
33
31
Original file line number Diff line number Diff line change @@ -11,15 +11,44 @@ class Settings(BaseSettings):
11
11
env_ignore_empty = True ,
12
12
extra = "ignore"
13
13
)
14
- redis_url : RedisDsn = os .getenv ("REDIS_URL" )
15
14
jwt_algorithm : str = os .getenv ("JWT_ALGORITHM" )
16
15
jwt_expire : int = os .getenv ("JWT_EXPIRE" )
17
16
17
+ REDIS_HOST : str
18
+ REDIS_PORT : int
19
+ REDIS_DB : str
20
+
21
+ JWT_ALGORITHM : str
22
+ JWT_EXPIRE : int
23
+
18
24
SQL_USER : str
19
25
SQL_PASS : str
20
26
SQL_HOST : str
21
27
SQL_DB : str
22
28
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
+
23
52
@computed_field
24
53
@property
25
54
def asyncpg_url (self ) -> PostgresDsn :
You can’t perform that action at this time.
0 commit comments