Пример #1
0
    def _write(self, command, future):
        """Write a command to the socket

        :param Command command: the Command data structure

        """
        def on_written():
            self._on_written(command, future)

        try:
            self._stream.write(command.command, callback=on_written)
        except iostream.StreamClosedError as error:
            future.set_exception(exceptions.ConnectionError(error))
        except Exception as error:
            LOGGER.exception('unhandled write failure - %r', error)
            future.set_exception(exceptions.ConnectionError(error))
Пример #2
0
 def _on_closed(self):
     """Invoked by connections when they are closed."""
     self._connected.clear()
     if not self._closing:
         if self._on_close_callback:
             self._on_close_callback()
         else:
             raise exceptions.ConnectionError('closed')
Пример #3
0
    def close(self):
        """Close the Redis server connection

        :raises: :class:`~tredis.exceptions.ConnectionError`

        """
        if not self._stream:
            raise exceptions.ConnectionError('Not connected')
        self._stream.close()
Пример #4
0
    def close(self):
        """Close the stream.

        :raises: :class:`tredis.exceptions.ConnectionError` if the
            stream is not currently connected

        """
        if self._stream is None:
            raise exceptions.ConnectionError('Not connected')
        self._stream.close()
Пример #5
0
    def close(self):
        """Close any open connections to Redis.

        :raises: :exc:`tredis.exceptions.ConnectionError`

        """
        if not self._connected.is_set():
            raise exceptions.ConnectionError('not connected')
        self._closing = True
        if self._clustering:
            for host in self._cluster.keys():
                self._cluster[host].close()
        elif self._connection:
            self._connection.close()
Пример #6
0
        def on_ready(connection_ready):
            """Invoked once the connection has been established

            :param connection_ready: The connection future
            :type connection_ready: tornado.concurrent.Future

            """
            connection_error = connection_ready.exception()
            if connection_error:
                return future.set_exception(connection_error)

            def on_written():
                """Invoked when the command has been written to the socket"""
                self._get_response(future, expectation, format_callback)

            try:
                self._stream.write(command, callback=on_written)
            except iostream.StreamClosedError as error:
                future.set_exception(exceptions.ConnectionError(error))
Пример #7
0
    def _on_cluster_data_moved(self, response, command, future):
        """Process the ``MOVED`` response from a Redis cluster node.

        :param bytes response: The response from the Redis server
        :param command: The command that was being executed
        :type command: tredis.client.Command
        :param future: The execution future
        :type future: tornado.concurrent.Future

        """
        LOGGER.debug('on_cluster_data_moved(%r, %r, %r)', response, command,
                     future)
        parts = response.split(' ')
        name = '{}:{}'.format(*common.split_connection_host_port(parts[2]))
        LOGGER.debug('Moved to %r', name)
        if name not in self._cluster:
            raise exceptions.ConnectionError(
                '{} is not connected'.format(name))
        self._cluster[name].execute(
            command._replace(connection=self._cluster[name]), future)