File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ POSTGRES_PASSWORD=secret
19
19
REDIS_HOST = redis
20
20
REDIS_PORT = 6379
21
21
REDIS_DB = 2
22
- REDIS_URL = " redis://${ REDIS_HOST } :${ REDIS_PORT } /${ REDIS_DB } "
23
22
24
23
JWT_EXPIRE = 3600
25
24
JWT_ALGORITHM = HS256
Original file line number Diff line number Diff line change 26
26
REDIS_HOST : 127.0.0.1
27
27
REDIS_PORT : 6379
28
28
REDIS_DB : 2
29
- REDIS_URL : redis://127.0.0.1:6379/2
30
29
JWT_EXPIRE : 3600
31
30
JWT_ALGORITHM : HS256
32
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