From 09541a4138cc70dbc3bbb80ac4f39159e9cc05cd Mon Sep 17 00:00:00 2001 From: Mikhail Khromov Date: Mon, 4 Mar 2024 23:44:57 +0300 Subject: [PATCH 1/3] move redis max connections to .env --- .env.example | 4 +++- src/config.py | 2 ++ src/redis.py | 4 +++- start-polling.py | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 2f0692f..008b1c9 100644 --- a/.env.example +++ b/.env.example @@ -33,4 +33,6 @@ ADMIN_LOGS_CHAT_ID=-1234 # tg chat id for admin logs VK_TOKEN=fppgmdbgonj # ocr -MYSTIC_TOKEN=444 \ No newline at end of file +MYSTIC_TOKEN=444 + +REDIS_MAX_CONNECTIONS=128 diff --git a/src/config.py b/src/config.py index 99b7c37..21c5313 100644 --- a/src/config.py +++ b/src/config.py @@ -32,6 +32,8 @@ class Config(BaseSettings): MYSTIC_TOKEN: str | None = None + REDIS_MAX_CONNECTIONS: int | None = None + # @model_validator(mode="after") # def validate_sentry_non_local(self) -> "Config": # if self.ENVIRONMENT.is_deployed and not self.SENTRY_DSN: diff --git a/src/redis.py b/src/redis.py index 7801186..492cb34 100644 --- a/src/redis.py +++ b/src/redis.py @@ -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) diff --git a/start-polling.py b/start-polling.py index dfa1543..3184a05 100644 --- a/start-polling.py +++ b/start-polling.py @@ -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) From 2db348ef00637c552c59ebb4e679c0f1c2886b26 Mon Sep 17 00:00:00 2001 From: Mikhail Khromov <44099594+VeryBigSad@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:00:41 +0300 Subject: [PATCH 2/3] Update redis.py --- src/redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis.py b/src/redis.py index 492cb34..e49fbd5 100644 --- a/src/redis.py +++ b/src/redis.py @@ -10,7 +10,7 @@ pool = aioredis.ConnectionPool.from_url( str(settings.REDIS_URL), max_connections=settings.REDIS_MAX_CONNECTIONS, - decode_responses=True + decode_responses=True, ) redis_client = aioredis.Redis(connection_pool=pool) From 12773bedf74ffb2b82d06d28ad0c91cac408a5a9 Mon Sep 17 00:00:00 2001 From: Mikhail Khromov <44099594+VeryBigSad@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:36:20 +0300 Subject: [PATCH 3/3] Update config.py --- src/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.py b/src/config.py index 21c5313..56a8050 100644 --- a/src/config.py +++ b/src/config.py @@ -32,7 +32,7 @@ class Config(BaseSettings): MYSTIC_TOKEN: str | None = None - REDIS_MAX_CONNECTIONS: int | None = None + REDIS_MAX_CONNECTIONS: int = 128 # @model_validator(mode="after") # def validate_sentry_non_local(self) -> "Config":