Skip to content

Commit

Permalink
move redis max connections to .env (#48)
Browse files Browse the repository at this point in the history
* move redis max connections to .env

* Update redis.py

* Update config.py
  • Loading branch information
VeryBigSad authored Mar 5, 2024
1 parent af4f97c commit 857f123
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ ADMIN_LOGS_CHAT_ID=-1234 # tg chat id for admin logs
VK_TOKEN=fppgmdbgonj

# ocr
MYSTIC_TOKEN=444
MYSTIC_TOKEN=444

REDIS_MAX_CONNECTIONS=128
2 changes: 2 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Config(BaseSettings):

MYSTIC_TOKEN: str | None = None

REDIS_MAX_CONNECTIONS: int = 128

# @model_validator(mode="after")
# def validate_sentry_non_local(self) -> "Config":
# if self.ENVIRONMENT.is_deployed and not self.SENTRY_DSN:
Expand Down
4 changes: 3 additions & 1 deletion src/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from src.models import CustomModel

pool = aioredis.ConnectionPool.from_url(
str(settings.REDIS_URL), max_connections=32, decode_responses=True
str(settings.REDIS_URL),
max_connections=settings.REDIS_MAX_CONNECTIONS,
decode_responses=True,
)
redis_client = aioredis.Redis(connection_pool=pool)

Expand Down
4 changes: 3 additions & 1 deletion start-polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

if __name__ == "__main__":
pool = aioredis.ConnectionPool.from_url(
str(settings.REDIS_URL), max_connections=10, decode_responses=True
str(settings.REDIS_URL),
max_connections=settings.REDIS_MAX_CONNECTIONS,
decode_responses=True
)
redis.redis_client = aioredis.Redis(connection_pool=pool)

Expand Down

0 comments on commit 857f123

Please sign in to comment.