diff options
author | Erik Johnston <erik@matrix.org> | 2020-10-02 09:57:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 09:57:12 +0100 |
commit | 6c5d5e507e629cf57ae8c1034879e8ffaef33e9f (patch) | |
tree | d7f1840507fca7a59ef0ffe0c5aafcff26274cae /synapse/replication/tcp/redis.py | |
parent | Add config option for always using "userinfo endpoint" for OIDC (#7658) (diff) | |
download | synapse-6c5d5e507e629cf57ae8c1034879e8ffaef33e9f.tar.xz |
Add unit test for event persister sharding (#8433)
Diffstat (limited to 'synapse/replication/tcp/redis.py')
-rw-r--r-- | synapse/replication/tcp/redis.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/synapse/replication/tcp/redis.py b/synapse/replication/tcp/redis.py index f225e533de..de19705c1f 100644 --- a/synapse/replication/tcp/redis.py +++ b/synapse/replication/tcp/redis.py @@ -15,7 +15,7 @@ import logging from inspect import isawaitable -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional import txredisapi @@ -228,3 +228,41 @@ class RedisDirectTcpReplicationClientFactory(txredisapi.SubscriberFactory): p.password = self.password return p + + +def lazyConnection( + reactor, + host: str = "localhost", + port: int = 6379, + dbid: Optional[int] = None, + reconnect: bool = True, + charset: str = "utf-8", + password: Optional[str] = None, + connectTimeout: Optional[int] = None, + replyTimeout: Optional[int] = None, + convertNumbers: bool = True, +) -> txredisapi.RedisProtocol: + """Equivalent to `txredisapi.lazyConnection`, except allows specifying a + reactor. + """ + + isLazy = True + poolsize = 1 + + uuid = "%s:%d" % (host, port) + factory = txredisapi.RedisFactory( + uuid, + dbid, + poolsize, + isLazy, + txredisapi.ConnectionHandler, + charset, + password, + replyTimeout, + convertNumbers, + ) + factory.continueTrying = reconnect + for x in range(poolsize): + reactor.connectTCP(host, port, factory, connectTimeout) + + return factory.handler |