...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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. | |
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.
Socket | The socket type e.g. asio::ip::tcp::socket. |
Definition at line 72 of file connection.hpp.
struct boost::redis::basic_connection::rebind_executor |
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. |
|
inlineexplicit |
Constructor.
ex | Executor on which connection operation will run. |
ctx | SSL context. |
max_read_size | Maximum read size that is passed to the internal asio::dynamic_buffer constructor. |
Definition at line 97 of file connection.hpp.
|
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.
req | Request. |
resp | Response. |
token | Completion token. |
For an example see cpp20_echo_server.cpp. The completion token must have the following signature
Where the second parameter is the size of the response received in bytes.
Definition at line 254 of file connection.hpp.
|
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)
.
token | Completion token. |
For an example see cpp20_subscriber.cpp. The completion token must have the following signature
Where the second parameter is the size of the push received in bytes.
Definition at line 193 of file connection.hpp.
|
inline |
Starts underlying connection operations.
This member function provides the following functionality
boost::redis::config::addr
.cfg
.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.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)
.
cfg | Configuration paramters. |
l | Logger object. The interface expected is specified in the class boost::redis::logger . |
token | Completion token. |
The completion token must have the following signature
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.
|
inline |
Cancel operations.
operation::exec
: Cancels operations started with async_exec
. Affects only requests that haven't been written yet. async_run
operation. async_receive
. op | The operation to be cancelled. |
Definition at line 273 of file connection.hpp.
|
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
.
ec | Contains the error if any occurred. |
Definition at line 208 of file connection.hpp.