async def execute(self, raise_on_error: bool = True):
        """Execute all the commands in the current pipeline"""
        stack = self.command_stack
        if not stack and not self.watching:
            return []
        if self.scripts:
            await self.load_scripts()
        if self.is_transaction or self.explicit_transaction:
            execute = self._execute_transaction
        else:
            execute = self._execute_pipeline

        conn = self.connection
        if not conn:
            conn = await self.connection_pool.get_connection("MULTI", self.shard_hint)
            # assign to self.connection so reset() releases the connection
            # back to the pool after we're done
            self.connection = conn
        conn = cast(Connection, conn)

        try:
            return await execute(conn, stack, raise_on_error)
        except (ConnectionError, TimeoutError) as e:
            await conn.disconnect()
            # if we were watching a variable, the watch is no longer valid
            # since this connection has died. raise a WatchError, which
            # indicates the user should retry this transaction.
            if self.watching:
                raise WatchError(
                    "A ConnectionError occurred on while " "watching one or more keys"
                ) from e
            # if retry_on_timeout is not set, or the error is not
            # a TimeoutError, raise it
            if not (conn.retry_on_timeout and isinstance(e, TimeoutError)):
                raise
            # retry a TimeoutError when retry_on_timeout is set
            return await execute(conn, stack, raise_on_error)
        finally:
            await self.reset()
Execute all the commands in the current pipeline
aioredis/client.py