-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
41 lines (33 loc) · 1.11 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from pydantic_settings import BaseSettings
from pydantic import BaseModel
import redis.asyncio as redis_async
from contextlib import asynccontextmanager
class RunConfig(BaseModel):
host: str = '0.0.0.0'
port: int = 8000
class Settings(BaseSettings):
run: RunConfig = RunConfig()
REDIS_PORT: int = 6379
REDIS_PASSWORD: str = "parol"
REDIS_HOST: str = "0.0.0.0"
BASE_URL: str = "http://0.0.0.0:8000"
BASE_DIR: str = os.path.abspath(os.path.dirname(__file__))
UPLOAD_DIR: str = os.path.join(BASE_DIR, 'app/uploads')
# Создание экземпляра настроек
settings = Settings()
# Формирование URL для подключения к Redis
redis_url = f"redis://:{settings.REDIS_PASSWORD}@{settings.REDIS_HOST}:{settings.REDIS_PORT}/0"
redis_client = redis_async.Redis(
host=settings.REDIS_HOST,
port=settings.REDIS_PORT,
db=0,
password=settings.REDIS_PASSWORD,
decode_responses=True,
)
@asynccontextmanager
async def session_getter():
async with redis_client as session:
print("open")
yield session
print("close")