summary refs log tree commit diff
path: root/synapse/server.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-04-22 18:30:10 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2021-04-22 18:30:10 +0100
commitcfa0cff6aa43d2ac7a2c47e0b22ab5ed7c4ac9b6 (patch)
treed9313328474e811ec0c00989197e2b637c4f3307 /synapse/server.py
parentMerge commit 'cee4010f9' into anoa/dinsic_release_1_31_0 (diff)
parentAdd type hints to various handlers. (#9223) (diff)
downloadsynapse-cfa0cff6aa43d2ac7a2c47e0b22ab5ed7c4ac9b6.tar.xz
Merge commit '1baab2035' into anoa/dinsic_release_1_31_0
Diffstat (limited to 'synapse/server.py')
-rw-r--r--synapse/server.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/synapse/server.py b/synapse/server.py

index cb98406faf..6ffb7e0fd9 100644 --- a/synapse/server.py +++ b/synapse/server.py
@@ -102,6 +102,7 @@ from synapse.notifier import Notifier from synapse.push.action_generator import ActionGenerator from synapse.push.pusherpool import PusherPool from synapse.replication.tcp.client import ReplicationDataHandler +from synapse.replication.tcp.external_cache import ExternalCache from synapse.replication.tcp.handler import ReplicationCommandHandler from synapse.replication.tcp.resource import ReplicationStreamer from synapse.replication.tcp.streams import STREAMS_MAP, Stream @@ -127,6 +128,8 @@ from synapse.util.stringutils import random_string logger = logging.getLogger(__name__) if TYPE_CHECKING: + from txredisapi import RedisProtocol + from synapse.handlers.oidc_handler import OidcHandler from synapse.handlers.saml_handler import SamlHandler @@ -710,6 +713,33 @@ class HomeServer(metaclass=abc.ABCMeta): def get_account_data_handler(self) -> AccountDataHandler: return AccountDataHandler(self) + @cache_in_self + def get_external_cache(self) -> ExternalCache: + return ExternalCache(self) + + @cache_in_self + def get_outbound_redis_connection(self) -> Optional["RedisProtocol"]: + if not self.config.redis.redis_enabled: + return None + + # We only want to import redis module if we're using it, as we have + # `txredisapi` as an optional dependency. + from synapse.replication.tcp.redis import lazyConnection + + logger.info( + "Connecting to redis (host=%r port=%r) for external cache", + self.config.redis_host, + self.config.redis_port, + ) + + return lazyConnection( + hs=self, + host=self.config.redis_host, + port=self.config.redis_port, + password=self.config.redis.redis_password, + reconnect=True, + ) + async def remove_pusher(self, app_id: str, push_key: str, user_id: str): return await self.get_pusherpool().remove_pusher(app_id, push_key, user_id)