Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Loading...
Searching...
No Matches
boost::redis::basic_connection< Executor > Class Template Reference

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

#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 ctx=asio::ssl::context{asio::ssl::context::tlsv12_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 ctx=asio::ssl::context{asio::ssl::context::tlsv12_client}, std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)())
 Constructor. More...
 
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 CompletionToken = asio::default_completion_token_t<executor_type>>
auto async_receive (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.
 
usage get_usage () const noexcept
 Returns connection usage information.
 
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.
 
std::size_t receive (system::error_code &ec)
 Receives server pushes synchronously without blocking. More...
 
void reset_stream ()
 Resets the underlying stream.
 
template<class Response >
void set_receive_response (Response &response)
 Sets the response object of async_receive operations.
 
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.

Constructor & Destructor Documentation

◆ basic_connection()

template<class Executor >
boost::redis::basic_connection< Executor >::basic_connection ( executor_type  ex,
asio::ssl::context  ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
std::size_t  max_read_size = (std::numeric_limits<std::size_t>::max)() 
)
inlineexplicit

Constructor.

Parameters
exExecutor on which connection operation will run.
ctxSSL context.
max_read_sizeMaximum read size that is passed to the internal asio::dynamic_buffer constructor.

Definition at line 97 of file connection.hpp.

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 254 of file connection.hpp.

◆ async_receive()

template<class Executor >
template<class CompletionToken = asio::default_completion_token_t<executor_type>>
auto boost::redis::basic_connection< Executor >::async_receive ( 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
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 193 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 155 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.

Definition at line 273 of file connection.hpp.

◆ receive()

template<class Executor >
std::size_t boost::redis::basic_connection< Executor >::receive ( system::error_code &  ec)
inline

Receives server pushes synchronously without blocking.

Receives a server push synchronously by calling try_receive on the underlying channel. If the operation fails because try_receive returns false, ec will be set to boost::redis::error::sync_receive_push_failed.

Parameters
ecContains the error if any occurred.
Returns
The number of bytes read from the socket.

Definition at line 208 of file connection.hpp.


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