def send_command(self, cmd: Command): """Send a command if connection has been established. Args: cmd (Command) """ string = "%s %s" % (cmd.NAME, cmd.to_line()) if "\n" in string: raise Exception("Unexpected newline in command: %r", string) encoded_string = string.encode("utf-8") # We use "redis" as the name here as we don't have 1:1 connections to # remote instances. tcp_outbound_commands_counter.labels(cmd.NAME, "redis").inc() async def _send(): with PreserveLoggingContext(): # Note that we use the other connection as we can't send # commands using the subscription connection. await self.outbound_redis_connection.publish( self.stream_name, encoded_string ) run_as_background_process("send-cmd", _send)
async def _async_send_command(self, cmd: Command): """Encode a replication command and send it over our outbound connection""" string = "%s %s" % (cmd.NAME, cmd.to_line()) if "\n" in string: raise Exception("Unexpected newline in command: %r", string) encoded_string = string.encode("utf-8") # We use "redis" as the name here as we don't have 1:1 connections to # remote instances. tcp_outbound_commands_counter.labels(cmd.NAME, "redis").inc() await make_deferred_yieldable( self.synapse_outbound_redis_connection.publish( self.synapse_stream_name, encoded_string))