summary refs log tree commit diff
path: root/synapse/server.py
diff options
context:
space:
mode:
authorJason Little <realtyem@gmail.com>2023-05-26 14:28:39 -0500
committerGitHub <noreply@github.com>2023-05-26 15:28:39 -0400
commitc835befd10ae0087c3c54a36989ba347313b68af (patch)
treeed898f1379a6e93a0351aad64023a9b073f7a48a /synapse/server.py
parentAdd `MSC3820opt2` as a known room version (#15678) (diff)
downloadsynapse-c835befd10ae0087c3c54a36989ba347313b68af.tar.xz
Add Unix socket support for Redis connections (#15644)
Adds a new configuration setting to connect to Redis via a Unix
socket instead of over TCP. Disabled by default.
Diffstat (limited to '')
-rw-r--r--synapse/server.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/synapse/server.py b/synapse/server.py
index f6e245569c..cce5fb66ff 100644
--- a/synapse/server.py
+++ b/synapse/server.py
@@ -864,22 +864,36 @@ class HomeServer(metaclass=abc.ABCMeta):
 
         # 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
+        from synapse.replication.tcp.redis import lazyConnection, lazyUnixConnection
 
-        logger.info(
-            "Connecting to redis (host=%r port=%r) for external cache",
-            self.config.redis.redis_host,
-            self.config.redis.redis_port,
-        )
+        if self.config.redis.redis_path is None:
+            logger.info(
+                "Connecting to redis (host=%r port=%r) for external cache",
+                self.config.redis.redis_host,
+                self.config.redis.redis_port,
+            )
 
-        return lazyConnection(
-            hs=self,
-            host=self.config.redis.redis_host,
-            port=self.config.redis.redis_port,
-            dbid=self.config.redis.redis_dbid,
-            password=self.config.redis.redis_password,
-            reconnect=True,
-        )
+            return lazyConnection(
+                hs=self,
+                host=self.config.redis.redis_host,
+                port=self.config.redis.redis_port,
+                dbid=self.config.redis.redis_dbid,
+                password=self.config.redis.redis_password,
+                reconnect=True,
+            )
+        else:
+            logger.info(
+                "Connecting to redis (path=%r) for external cache",
+                self.config.redis.redis_path,
+            )
+
+            return lazyUnixConnection(
+                hs=self,
+                path=self.config.redis.redis_path,
+                dbid=self.config.redis.redis_dbid,
+                password=self.config.redis.redis_password,
+                reconnect=True,
+            )
 
     def should_send_federation(self) -> bool:
         "Should this server be sending federation traffic directly?"