File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
packages/service-library/src/servicelib/redis Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class RedisClientSDK:
3434 client_name : str
3535 decode_responses : bool = DEFAULT_DECODE_RESPONSES
3636 health_check_interval : datetime .timedelta = DEFAULT_HEALTH_CHECK_INTERVAL
37+ with_health_check : bool = True
3738
3839 _client : aioredis .Redis = field (init = False )
3940 _health_check_task : Task | None = None
@@ -69,10 +70,11 @@ async def _periodic_check_health() -> None:
6970 self ._health_check_task_started_event .set ()
7071 self ._is_healthy = await self .ping ()
7172
72- self ._health_check_task = asyncio .create_task (
73- _periodic_check_health (),
74- name = f"redis_service_health_check_{ self .redis_dsn } __{ uuid4 ()} " ,
75- )
73+ if self .with_health_check :
74+ self ._health_check_task = asyncio .create_task (
75+ _periodic_check_health (),
76+ name = f"redis_service_health_check_{ self .redis_dsn } __{ uuid4 ()} " ,
77+ )
7678
7779 _logger .info (
7880 "Connection to %s succeeded with %s" ,
Original file line number Diff line number Diff line change @@ -20,13 +20,18 @@ class RedisClientsManager:
2020 _client_sdks : dict [RedisDatabase , RedisClientSDK ] = field (default_factory = dict )
2121
2222 async def setup (self ) -> None :
23+ use_health_check = True
2324 for config in self .databases_configs :
2425 self ._client_sdks [config .database ] = RedisClientSDK (
2526 redis_dsn = self .settings .build_redis_dsn (config .database ),
2627 decode_responses = config .decode_responses ,
2728 health_check_interval = config .health_check_interval ,
2829 client_name = f"{ self .client_name } " ,
30+ with_health_check = use_health_check ,
2931 )
32+ # NOTE: disables health check for all clients except the first
33+ # reduces health check requests to Redis
34+ use_health_check = False
3035
3136 async def shutdown (self ) -> None :
3237 await asyncio .gather (
You can’t perform that action at this time.
0 commit comments