boost::redis::basic_connection::async_run :: Boost.Redis

# boost::redis::basic_connection::async_run

Starts the underlying connection operations.

## Synopsis

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

    template<class CompletionToken = asio::default_completion_token_t<executor_type>>
    auto
    async_run(
        config const& cfg,
        CompletionToken&& token = {});

## Description

This function establishes a connection to the Redis server and keeps it healthy by performing the following operations:

- For Sentinel deployments (`config::sentinel::addresses` is not empty), contacts Sentinels to obtain the address of the configured master.

- For TCP connections, resolves the server hostname passed in `boost::redis::config::addr`.

- Establishes a physical connection to the server. For TCP connections, connects to one of the endpoints obtained during name resolution. For UNIX domain socket connections, it connects to `boost::redis::config::unix_socket`.

- If `boost::redis::config::use_ssl` is `true`, performs the TLS handshake.

- Executes the setup request, as defined by the passed `config` object. By default, this is a `HELLO` command, but it can contain any other arbitrary commands. See the `config::setup` docs for more info.

- Starts a health‐check operation where `PING` commands are sent at intervals specified by `config::health_check_interval` when the connection is idle. See the documentation of `config::health_check_interval` for more info.

- Starts read and write operations. Requests issued using `async_exec` before `async_run` is called will be written to the server immediately.

When a connection is lost for any reason, a new one is established automatically. To disable reconnection set `boost::redis::config::reconnect_wait_interval` to zero.

The completion token must have the following signature

    void f(system::error_code);

## Per‐operation cancellation

This operation supports the following cancellation types:

- `asio::cancellation_type_t::terminal`.

- `asio::cancellation_type_t::partial`.

In both cases, cancellation is equivalent to calling `basic_connection::cancel` passing `operation::run` as argument.

After the operation completes, the token's associated cancellation slot may still have a cancellation handler associated to this connection. You should make sure to not invoke it after the connection has been destroyed. This is consistent with what other Asio I/O objects do.

For example on how to call this function refer to cpp20_intro.cpp or any other example.

## Parameters

Name | Description
--- | ---
cfg | Configuration parameters.
token | Completion token.

Created with MrDocs