def test_lazy_connect_timeout(self): c = redis.lazyConnection(host = "10.255.255.1", port = 8000, reconnect = True, connectTimeout = 1.0, replyTimeout = 10.0) c._factory.maxRetries = 1 p = c.ping() # this does seem to take a bit too long yield self.assertFailure(p, error.TimeoutError) yield c.disconnect()
def start_replication(self, hs): """Helper method to start a replication connection to the remote server using TCP. """ if hs.config.redis.redis_enabled: import txredisapi from synapse.replication.tcp.redis import ( RedisDirectTcpReplicationClientFactory, ) logger.info( "Connecting to redis (host=%r port=%r)", hs.config.redis_host, hs.config.redis_port, ) # First let's ensure that we have a ReplicationStreamer started. hs.get_replication_streamer() # We need two connections to redis, one for the subscription stream and # one to send commands to (as you can't send further redis commands to a # connection after SUBSCRIBE is called). # First create the connection for sending commands. outbound_redis_connection = txredisapi.lazyConnection( host=hs.config.redis_host, port=hs.config.redis_port, password=hs.config.redis.redis_password, reconnect=True, ) # Now create the factory/connection for the subscription stream. self._factory = RedisDirectTcpReplicationClientFactory( hs, outbound_redis_connection) hs.get_reactor().connectTCP( hs.config.redis.redis_host, hs.config.redis.redis_port, self._factory, ) else: client_name = hs.get_instance_name() self._factory = DirectTcpReplicationClientFactory( hs, client_name, self) host = hs.config.worker_replication_host port = hs.config.worker_replication_port hs.get_reactor().connectTCP(host, port, self._factory)
def test_lazyConnection(self): db = redis.lazyConnection(redis_host, redis_port, reconnect=False) self.assertEqual(isinstance(db._connected, defer.Deferred), True) db = yield db._connected self.assertEqual(isinstance(db, redis.ConnectionHandler), True) yield db.disconnect()
def test_lazyConnection(self): db = txredisapi.lazyConnection(redis_host, redis_port, reconnect=False) yield self._wait_for_lazy_connection(db) yield self._assert_simple_sets_on_pipeline(db=db) yield db.disconnect()
def test_lazyConnection(self): db = txredisapi.lazyConnection(REDIS_HOST, REDIS_PORT, reconnect=False) yield self._wait_for_lazy_connection(db) yield self._assert_simple_sets_on_pipeline(db=db) yield db.disconnect()
def setup(self): # read settings from a conf file or something... RedisMixin.rc = redis.lazyConnection(port=REDIS_CONFIG["port"])
from autobahn.twisted.websocket import WebSocketServerProtocol, \ WebSocketServerFactory from twisted.internet import reactor import txredisapi as redis import json rc = redis.lazyConnection(host='127.0.0.1', port=6379, dbid=0) from channelserver import myFactory class Serverprotocol(WebSocketServerProtocol): def onConnect(self, request): try: self.userName = request.params['user'][0] self.channel = request.params['channel'][0] print("Client connecting: {0}".format(request.peer)) reactor.connectTCP('127.0.0.1', 6379, myFactory(self)) except KeyError as e: self.userName = None self.channel = None def onOpen(self): if self.userName is None or self.channel is None: self.sendClose() print("WebSocket connection open.") def onMessage(self, payload, isBinary): message = json.dumps({ "from": self.userName, "message": payload.decode('utf8') })