boost_redis 1.4.2
A redis client library
boost::redis::basic_connection< Executor > Class Template Reference

A SSL connection to the Redis server. More...

#include <include/boost/redis/connection.hpp>

Classes

struct  rebind_executor
 Rebinds the socket type to another executor. More...
 

Public Types

using executor_type = Executor
 Executor type.
 

Public Member Functions

 basic_connection (asio::io_context &ioc, asio::ssl::context::method method=asio::ssl::context::tls_client, std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)())
 Contructs from a context.
 
 basic_connection (executor_type ex, asio::ssl::context::method method=asio::ssl::context::tls_client, std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)())
 Contructs from an executor.
 
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=CompletionToken{})
 Executes commands on the Redis server asynchronously. More...
 
template<class Response = ignore_t, class CompletionToken = asio::default_completion_token_t<executor_type>>
auto async_receive (Response &response, CompletionToken token=CompletionToken{})
 Receives server side pushes asynchronously. More...
 
template<class Logger = logger, class CompletionToken = asio::default_completion_token_t<executor_type>>
auto async_run (config const &cfg={}, Logger l=Logger{}, CompletionToken token=CompletionToken{})
 Starts underlying connection operations. More...
 
void cancel (operation op=operation::all)
 Cancel operations. More...
 
executor_type get_executor () noexcept
 Returns the underlying executor.
 
auto const & get_ssl_context () const noexcept
 Returns the ssl context.
 
auto & get_ssl_context () noexcept
 Returns the ssl context.
 
auto const & next_layer () const noexcept
 Returns a const reference to the next layer.
 
auto & next_layer () noexcept
 Returns a reference to the next layer.
 
void reset_stream ()
 Resets the underlying stream.
 
bool will_reconnect () const noexcept
 Returns true if the connection was canceled.
 

Detailed Description

template<class Executor>
class boost::redis::basic_connection< Executor >

A SSL connection to the Redis server.

This class keeps a healthy connection to the Redis instance where commands can be sent at any time. For more details, please see the documentation of each individual function.

Template Parameters
SocketThe socket type e.g. asio::ip::tcp::socket.

Definition at line 72 of file connection.hpp.


Class Documentation

◆ boost::redis::basic_connection::rebind_executor

struct boost::redis::basic_connection::rebind_executor
template<class Executor>
template<class Executor1>
struct boost::redis::basic_connection< Executor >::rebind_executor< Executor1 >

Rebinds the socket type to another executor.

Definition at line 83 of file connection.hpp.

Class Members
typedef basic_connection< Executor1 > other The connection type when rebound to the specified executor.

Member Function Documentation

◆ async_exec()

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

Executes commands on the Redis server asynchronously.

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.

Parameters
reqRequest.
respResponse.
tokenCompletion token.

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.

Definition at line 227 of file connection.hpp.

◆ async_receive()

template<class Executor >
template<class Response = ignore_t, class CompletionToken = asio::default_completion_token_t<executor_type>>
auto boost::redis::basic_connection< Executor >::async_receive ( Response &  response,
CompletionToken  token = CompletionToken{} 
)
inline

Receives server side pushes asynchronously.

When pushes arrive and there is no async_receive operation in progress, pushed data, requests, and responses will be paused until async_receive is called again. Apps will usually want to call async_receive in a loop.

To cancel an ongoing receive operation apps should call connection::cancel(operation::receive).

Parameters
responseResponse object.
tokenCompletion token.

For an example see cpp20_subscriber.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 push received in bytes.

Definition at line 192 of file connection.hpp.

◆ async_run()

template<class Executor >
template<class Logger = logger, class CompletionToken = asio::default_completion_token_t<executor_type>>
auto boost::redis::basic_connection< Executor >::async_run ( config const &  cfg = {},
Logger  l = Logger{},
CompletionToken  token = CompletionToken{} 
)
inline

Starts underlying connection operations.

This member function provides the following functionality

  1. Resolve the address passed on boost::redis::config::addr.
  2. Connect to one of the results obtained in the resolve operation.
  3. Send a HELLO command where each of its parameters are read from cfg.
  4. Start a health-check operation where ping commands are sent at intervals specified in boost::redis::config::health_check_interval. The message passed to PING will be boost::redis::config::health_check_id. Passing a timeout with value zero will disable health-checks. If the Redis server does not respond to a health-check within two times the value specified here, it will be considered unresponsive and the connection will be closed and a new connection will be stablished.
  5. Starts read and write operations with the Redis server. More specifically it will trigger the write of all requests i.e. calls to async_exec that happened prior to this call.

When a connection is lost for any reason, a new one is stablished automatically. To disable reconnection call boost::redis::connection::cancel(operation::reconnection).

Parameters
cfgConfiguration paramters.
lLogger object. The interface expected is specified in the class boost::redis::logger.
tokenCompletion token.

The completion token must have the following signature

void f(system::error_code);

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

Definition at line 149 of file connection.hpp.

◆ cancel()

template<class Executor >
void boost::redis::basic_connection< Executor >::cancel ( operation  op = operation::all)
inline

Cancel operations.

Parameters
opThe operation to be cancelled.
Returns
The number of operations that have been canceled.

Definition at line 247 of file connection.hpp.


The documentation for this class was generated from the following file: