# boost::redis::basic_connection::async_exec

Executes commands on the Redis server asynchronously.

## Synopsis

Declared in `<boost/redis/connection.hpp>`

    template<
        class Response = ignore_t,
        class CompletionToken = asio::default_completion_token_t<executor_type>>
    auto
    async_exec(
        request const& req,
        Response& resp = ignore,
        CompletionToken&& token = {});

## Description

This function sends a request to the Redis server and waits for the responses to each individual command in the request. If the request contains only commands that don't expect a response, the completion occurs after it has been written to the underlying stream. Multiple concurrent calls to this function will be automatically queued by the implementation.

For an example see cpp20_echo_server.cpp.

The completion token must have the following signature:

    void f(system::error_code, std::size_t);

Where the second parameter is the size of the response received in bytes.

## Per‐operation cancellation

This operation supports per‐operation cancellation. Depending on the state of the request when cancellation is requested, we can encounter two scenarios:

- If the request hasn't been sent to the server yet, cancellation will prevent it from being sent to the server. In this situation, all cancellation types are supported (`asio::cancellation_type_t::terminal`, `asio::cancellation_type_t::partial` and `asio::cancellation_type_t::total`).

- If the request has been sent to the server but the response hasn't arrived yet, cancellation will cause `async_exec` to complete immediately. When the response arrives from the server, it will be ignored. In this situation, only `asio::cancellation_type_t::terminal` and `asio::cancellation_type_t::partial` are supported. Cancellation requests specifying `asio::cancellation_type_t::total` only will be ignored.

In any case, connections can be safely used after cancelling `async_exec` operations.

## Object lifetimes

Both `req` and `res` should be kept alive until the operation completes. No copies of the request object are made.

## Parameters

Name | Description
--- | ---
req | The request to be executed.
resp | The response object to parse data into.
token | Completion token.

Created with MrDocs