### Example of Constructing a Redis Request Pipeline Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request This example demonstrates how to create a `request` object and append multiple Redis commands to it, forming a pipeline. It utilizes the `push` member function to add commands sequentially. ```cpp request r; r.push("HELLO", 3); r.push("FLUSHALL"); r.push("PING"); r.push("PING", "key"); r.push("QUIT"); ``` -------------------------------- ### Start Connection Operations (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_run-0b Starts the underlying connection operations for a basic Redis connection using a default configuration. This function is deprecated and users should prefer the overload that accepts an explicit configuration object. It takes a completion token as input. ```cpp template> auto async_run(CompletionToken&& token = {}); ``` -------------------------------- ### Redis-plus-plus: Asynchronous Operations with Futures in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/comparison Illustrates the asynchronous interface of redis-plus-plus using Futures. This example shows initiating an asynchronous ping command and retrieving its result. It highlights that the async interface relies on futures, which can have performance implications, and that async operations are started on every command instead of being enqueued. ```cpp auto async_redis = AsyncRedis(opts, pool_opts); Future ping_res = async_redis.ping(); cout << ping_res.get() << endl; ``` -------------------------------- ### Boost.Redis Connection Constructor (io_context) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-049 Constructs a boost::redis::connection object using an asio::io_context. Allows for specifying an SSL context and logger for connection setup and operation. The io_context handles asynchronous operations. ```cpp explicit connection( asio::io_context& ioc, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` ```cpp connection( asio::io_context& ioc, logger lgr); ``` -------------------------------- ### Boost.Redis: Commands, Pipelines, and Transactions in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/comparison Demonstrates how to send individual commands, create pipelines for multiple commands, and execute transactions using the Boost.Redis library. It shows setting and getting keys, creating a pipeline with various operations, and initiating a transaction with increment and multi-get commands. The replies from pipelines and transactions can be parsed by type and index. ```cpp auto redis = Redis("tcp://127.0.0.1:6379"); // Send commands redis.set("key", "val"); auto val = redis.get("key"); // val is of type OptionalString. if (val) std::cout << *val << std::endl; // Sending pipelines auto pipe = redis.pipeline(); auto pipe_replies = pipe.set("key", "value") .get("key") .rename("key", "new-key") .rpush("list", {"a", "b", "c"}) .lrange("list", 0, -1) .exec(); // Parse reply with reply type and index. auto set_cmd_result = pipe_replies.get(0); // ... // Sending a transaction auto tx = redis.transaction(); auto tx_replies = tx.incr("num0") .incr("num1") .mget({"num0", "num1"}) .exec(); auto incr_result0 = tx_replies.get(0); // ... ``` -------------------------------- ### boost::redis::basic_connection::async_run (Deprecated) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_run-0b Starts the underlying connection operations using a default-constructed config object. This function is deprecated and users should prefer the overload that takes an explicit config object. ```APIDOC ## boost::redis::basic_connection::async_run ### Description Uses a default-constructed config object to run the connection. ### Method `auto async_run(CompletionToken&& token = {});` ### Endpoint N/A (This is a library function, not a REST API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // This is a C++ library function, not a request body example. // See Synopsis for usage. ``` ### Response #### Success Response N/A (This is a C++ library function, not a response example.) #### Response Example ```cpp // This is a C++ library function, not a response example. ``` ### Deprecated This function is deprecated and will be removed in subsequent releases. Use the overload taking an explicit config object, instead. ``` -------------------------------- ### C++ Tutorial: PING Redis Server Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/index This C++ code snippet demonstrates how to establish a short-lived connection to a Redis server using Boost.Redis and execute a PING command. It utilizes Boost.Asio's coroutines for asynchronous operations. The example shows request creation, response handling, and printing the server's reply. ```cpp #include #include #include #include #include namespace net = boost::asio; using boost::redis::request; using boost::redis::response; using boost::redis::config; using boost::redis::connection; auto co_main(config const& cfg) -> net::awaitable { auto conn = std::make_shared(co_await net::this_coro::executor); conn->async_run(cfg, {}, net::consign(net::detached, conn)); // A request containing only a ping command. request req; req.push("PING", "Hello world"); // Response object. response resp; // Executes the request. co_await conn->async_exec(req, resp); conn->cancel(); std::cout << "PING: " << std::get<0>(resp).value() << std::endl; } ``` -------------------------------- ### Constructing a Redis Request Pipeline (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Demonstrates how to build a `boost::redis::request` object by pushing individual commands and ranges of arguments. This is useful for sending multiple Redis commands in a single network round trip, known as a pipeline. The example shows pushing string arguments, a list, and a map. ```cpp // Some example containers. std::list list {...}; std::map map { ...}; // The request can contain multiple commands. request req; // Command with variable length of arguments. req.push("SET", "key", "some value", "EX", "2"); // Pushes a list. req.push_range("SUBSCRIBE", list); // Same as above but as an iterator range. req.push_range("SUBSCRIBE", std::cbegin(list), std::cend(list)); // Pushes a map. req.push_range("HSET", "key", map); ``` -------------------------------- ### Example Usage of boost::redis::ignore_t Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/ignore_t Demonstrates how to use boost::redis::ignore_t to selectively ignore responses in a Redis operation. This example shows ignoring the first and third elements of a multi-part response. Note that RESP3 errors are not ignored and will result in an error. ```cpp response resp; ``` -------------------------------- ### Call boost::redis::connection::async_run (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/async_run-0e This C++ function is used to start an asynchronous operation on a Redis connection. It takes configuration parameters, a logger, and a completion token. The logger provided here overwrites any logger set during connection construction. This function is deprecated. ```cpp template auto async_run( config const& cfg, logger l, CompletionToken&& token = {}); ``` -------------------------------- ### Get Redis Config Reference Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/get_config-0c Returns a constant reference to the configuration object associated with a Redis request. This function is declared in the header and is marked as noexcept, indicating it will not throw exceptions. It is useful for inspecting or accessing the current configuration settings of the Redis request object. ```cpp #include // ... within a class or context where get_config is defined ... [[nodiscard]] const config& get_config() const noexcept; ``` -------------------------------- ### async_run with Config and Completion Token - Boost.Redis Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_run-04 Starts the underlying connection operations using configuration parameters and an optional completion token. This is the primary overload that accepts a config object and uses asio's completion token pattern for async operations. Returns an auto-deduced type based on the completion token provided. ```cpp template> auto async_run( config const& cfg, CompletionToken&& token = {}); ``` -------------------------------- ### Get Connection Usage Information (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/get_usage Retrieves the current usage statistics for a Redis connection. This function is declared in `` and returns connection usage information. ```cpp usage get_usage() const noexcept; ``` -------------------------------- ### Get Immutable Redis Configuration (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/get_config-03 This function returns a constant reference to the configuration object associated with the Redis request. It is declared in the `` header. This is useful for inspecting settings without modifying them. ```cpp [[nodiscard]] config const& get_config() const noexcept; ``` -------------------------------- ### Get Suggested Buffer Growth for RESP3 Parsing (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/resp3/parser/get_suggested_buffer_growth The get_suggested_buffer_growth function, declared in , suggests an appropriate buffer size for RESP3 parsing based on a provided hint. It is a const noexcept function returning std::size_t. ```cpp std::size_t get_suggested_buffer_growth(std::size_t hint) const noexcept; ``` -------------------------------- ### Get SSL Context (C++) - Deprecated Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/get_ssl_context Retrieves the SSL context from a basic_connection. This method is deprecated because ssl::context lacks const methods. SSL configuration should be performed by passing an ssl::context to the connection's constructor. ```cpp #include // ... other code ... asio::ssl::context const& get_ssl_context() const noexcept; ``` -------------------------------- ### Get Connection Usage Information with C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/get_usage The `get_usage()` function, declared in ``, returns connection usage information for a basic Redis connection. It is a const and noexcept method, ensuring it does not modify the connection state and can be safely called without exceptions. The return type is the connection's usage information. ```cpp usage get_usage() const noexcept; ``` -------------------------------- ### Mapping Redis RESP3 Types to C++ with Boost.Redis (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Provides an example of how to define a `boost::redis::response` object for a complex request involving various Redis commands and data types. It maps RESP3 types like 'hello', 'rpush', 'hset', 'lrange', 'hgetall', and 'quit' to corresponding C++ types, including aggregates like `std::vector` and `std::map`. ```cpp request req; req.push("HELLO", 3); req.push_range("RPUSH", "key1", vec); req.push_range("HSET", "key2", map); req.push("LRANGE", "key3", 0, -1); req.push("HGETALL", "key4"); req.push("QUIT"); response< redis::ignore_t, // hello int, // rpush int, // hset std::vector, // lrange std::map, // hgetall std::string // quit > resp; ``` -------------------------------- ### async_run Template Function Declaration - Boost.Redis Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_run-07 Declares the async_run template member function for boost::redis::basic_connection that starts underlying connection operations. Accepts configuration, logger, and optional completion token parameters. Returns an auto-deduced type based on the completion token. This function is deprecated and should be replaced with the overload that omits the logger parameter. ```cpp template> auto async_run( config const& cfg, logger l, CompletionToken&& token = {}); ``` -------------------------------- ### boost::redis::basic_connection::basic_connection Constructor Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-07 Constructs a boost::redis::basic_connection object. An SSL context with default settings will be created. This constructor takes an executor for I/O operations and a logger for configuration. ```APIDOC ## boost::redis::basic_connection::basic_connection Constructor ### Description Constructor from an executor and a logger. An SSL context with default settings will be created. ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```cpp // Assuming 'ex' is an executor and 'lgr' is a logger object boost::redis::basic_connection connection(ex, lgr); ``` ### Response #### Success Response N/A (Constructor) #### Response Example N/A (Constructor) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters Name | Description ---|--- **ex** | Executor used to create all internal I/O objects. **lgr** | Logger configuration. It can be used to filter messages by level and customize logging. By default, `logger::level::info` messages and higher are logged to `stderr`. ``` -------------------------------- ### Constructor for boost::redis::basic_connection Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-0f Initializes a basic Redis connection using an io_context. It accepts an optional SSL context and a logger configuration for customizing logging behavior. ```cpp explicit basic_connection( asio::io_context& ioc, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` -------------------------------- ### Get Underlying SSL Stream (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/next_layer-09 The `next_layer` function, declared in ``, returns a reference to the underlying SSL stream object. This function is deprecated. It is available in both non-const and const overloads. ```cpp auto& next_layer() noexcept; auto const& next_layer() const noexcept; ``` -------------------------------- ### Boost.Redis basic_connection Constructor with io_context Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-0c Constructs a basic_connection using an asio::io_context, with optional SSL context and logger configurations. The io_context manages the I/O operations. The logger allows for message filtering and custom logging. ```cpp explicit basic_connection( asio::io_context& ioc, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` ```cpp basic_connection( asio::io_context& ioc, logger lgr); ``` -------------------------------- ### Initialize boost::redis::basic_connection Constructor (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-07 Constructs a basic_connection object for boost::redis. It requires an executor for I/O operations and a logger for message filtering and customization. An SSL context with default settings is automatically created. ```cpp basic_connection( executor_type ex, logger lgr); ``` -------------------------------- ### Get boost::redis::resp3::bulk_counter::size Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/resp3/bulk_counter-01/size Retrieves the size of boost::redis::resp3::bulk_counter. This is a constexpr static variable, meaning its value is determined at compile time. It is declared in the header. ```cpp inline constexpr static auto size = 1U; ``` -------------------------------- ### Get Mutable Redis Configuration (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/get_config-03 This function returns a mutable reference to the configuration object associated with the Redis request, allowing for modifications. It is declared in ``. Use this when you need to change request-specific settings. ```cpp [[nodiscard]] config& get_config() noexcept; ``` -------------------------------- ### Get SSL Context (Deprecated) - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/get_ssl_context Retrieves the SSL context for a Redis connection. This function is deprecated because `asio::ssl::context` lacks const methods, and TLS configuration should be handled during connection construction. ```cpp asio::ssl::context const& get_ssl_context() const noexcept; ``` -------------------------------- ### Initialize basic_connection with io_context and logger (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-0d This constructor initializes a basic_connection for Boost.Redis. It requires an asio::io_context for I/O operations and a logger object for managing and filtering log messages. The logger can be configured for different levels and output destinations, with a default setting to log info level messages and higher to stderr. ```cpp basic_connection( asio::io_context& ioc, logger lgr); ``` -------------------------------- ### boost::redis::connection::connection Constructor Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-047 Constructor for establishing a new Redis connection. It takes an executor for I/O operations and a logger for configuration. ```APIDOC ## boost::redis::connection::connection Constructor ### Description Constructor from an executor and a logger. An SSL context with default settings will be created. ### Method Constructor ### Endpoint N/A (Class Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp boost::redis::connection::executor_type ex = ...; // Obtain an executor boost::redis::logger lgr = ...; // Obtain a logger boost::redis::connection conn(ex, lgr); ``` ### Response #### Success Response (Constructor) Initializes a new `boost::redis::connection` object. #### Response Example N/A (Constructor does not return a value in the typical sense) ``` -------------------------------- ### Constructing Redis Requests Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Demonstrates how to build a Redis request object by pushing individual commands or ranges of arguments. This includes commands with variable arguments and PUSH operations for collections. ```APIDOC ## Constructing Redis Requests ### Description Redis requests are composed of one or more commands, often referred to as pipelines. This section shows how to build these requests using the `boost::redis::request` object. ### Method N/A (Object Construction and Method Calls) ### Endpoint N/A (Client-side construction) ### Parameters N/A ### Request Example ```cpp // Example containers std::list list_args = {"val1", "val2"}; std::map map_args = {{"field1", "value1"}, {"field2", "value2"}}; // Create a request object boost::redis::request req; // Command with variable length arguments req.push("SET", "mykey", "myvalue", "EX", "60"); // Push arguments from a list req.push_range("SUBSCRIBE", list_args); // Push arguments from a list using iterators req.push_range("PUBLISH", std::cbegin(list_args), std::cend(list_args)); // Push arguments from a map (e.g., for HSET) req.push_range("HSET", "myhash", map_args); ``` ### Response N/A (This is for request construction) ``` -------------------------------- ### Get Command Count - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/get_commands Retrieves the number of commands currently stored within a boost::redis::request object. This function is declared in `` and returns a std::size_t representing the command count. It is a noexcept operation. ```cpp #include // Assuming 'request' is an instance of boost::redis::request std::size_t command_count = request.get_commands(); ``` -------------------------------- ### Boost.Redis Functions Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis This section details the functions provided by the Boost.Redis library. ```APIDOC ## Functions ### Description Functions provide utility and operational capabilities for interacting with Redis. | Name | Description | |---|---| | `make_error_code` | Creates a error_code object from an error. | | `consume_one` | `consume_one` overloads | ``` -------------------------------- ### Get Expected Responses for Redis Request (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/get_expected_responses Retrieves the count of responses anticipated from a Redis request. This function is part of the boost::redis library and is declared in ``. It returns a `std::size_t` indicating the expected number of responses. ```cpp #include // ... within a boost::redis::request object ... std::size_t expected_responses = request.get_expected_responses(); ``` -------------------------------- ### Construct boost::redis::connection with io_context and SSL Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-0e Creates a new Redis connection object using an ASIO io_context, SSL context, and optional logger. The constructor initializes all internal I/O objects and configures SSL/TLS settings for secure communication. Parameters include the I/O context for async operations, SSL context (defaulting to TLSv12 client mode), and optional logger for filtering and customizing log messages. ```cpp explicit connection( asio::io_context& ioc, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` -------------------------------- ### Boost.Redis Connection Constructor (Executor) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-049 Constructs a boost::redis::connection object using an executor. Supports optional SSL context and logger configuration. The executor manages internal I/O operations. ```cpp explicit connection( executor_type ex, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` ```cpp connection( executor_type ex, logger lgr); ``` -------------------------------- ### Get Executor from boost::redis::basic_connection Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/get_executor The `get_executor` function in `boost::redis::basic_connection` returns the executor associated with the connection. This function is declared in `` and is marked as `noexcept`, indicating it does not throw exceptions. It returns an object of type `executor_type`. ```cpp executor_type get_executor() noexcept; ``` -------------------------------- ### boost::redis::connection::connection Constructor (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-047 Constructs a boost::redis::connection object using a provided executor and logger. An SSL context with default settings is automatically created. The executor manages I/O operations, and the logger configures message filtering and output. ```cpp #include // ... // Assuming 'ex' is an executor_type and 'lgr' is a logger boost::redis::connection::connection(ex, lgr); ``` -------------------------------- ### Get Next Layer of Connection (Deprecated) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/next_layer-01 This function, declared in ``, is a deprecated method that returns the underlying next layer of the connection, typically an asio::ssl::stream wrapping a tcp::socket. It provides access to the lower-level transport mechanism. ```cpp asio::ssl::stream const& next_layer() const noexcept; ``` -------------------------------- ### Create boost::redis::connection with io_context and logger Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-0c Constructor that initializes a Redis connection object from an ASIO io_context and logger configuration. The io_context is used to create all internal I/O objects, while the logger enables message filtering by level and customization of logging behavior. By default, info-level messages and higher are logged to stderr. ```cpp connection( asio::io_context& ioc, logger lgr); ``` -------------------------------- ### Processing Transaction Responses in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Illustrates how to define the response type for Redis transactions. Transaction commands are queued, and their individual responses are nested within the final EXEC command's response. The example shows ignoring queued responses and parsing the result of EXEC. ```cpp req.push("MULTI"); req.push("GET", "key1"); req.push("LRANGE", "key2", 0, -1); req.push("HGETALL", "key3"); req.push("EXEC"); ``` ```cpp response< ignore_t, // multi ignore_t, // QUEUED ignore_t, // QUEUED ignore_t, // QUEUED response< std::optional, // get std::optional>, // lrange std::optional> // hgetall > // exec > resp; ``` -------------------------------- ### Construct boost::redis::basic_connection with Executor Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-0b This constructor initializes a basic_connection object using a provided executor for I/O operations. It optionally accepts an SSL context for secure connections and a logger for message filtering and customization. The default logger logs info level messages and higher to stderr. ```cpp explicit basic_connection( executor_type ex, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` -------------------------------- ### Configure Boost.Redis Logging Level Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/logging This C++ example shows how to configure Boost.Redis logging to only output messages with a severity level of 'error' or higher. This is achieved by creating a logger object with `logger::level::error` and passing it to the connection constructor, effectively filtering out informational messages. ```cpp asio::io_context ioc; // Logs to stderr messages with severity >= level::error. // This will hide all informational output. connection conn {ioc, logger{logger::level::error}}; ``` -------------------------------- ### Get Next Layer Reference (Deprecated) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/next_layer-0f Retrieves a reference to the underlying stream layer of a Redis connection. This function is deprecated and will be removed in a future release. For UNIX domain sockets, it returns a dummy object. Use other member functions for connection interaction. ```cpp #include // ... auto& connection_ref = basic_connection_object.next_layer(); ``` -------------------------------- ### Call boost::redis::basic_connection::async_run Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/async_run-0f This C++ function, async_run, is part of the boost::redis library and is used to initiate an asynchronous run operation on a Redis connection. It takes configuration parameters and a completion token as input. The function is declared in the header. ```cpp template auto async_run( config const& cfg, CompletionToken&& token = {}); ``` -------------------------------- ### Default Constructor for boost::redis::resp3::parser::parser Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/resp3/parser/2constructor This snippet shows the default constructor for the parser class within the boost::redis::resp3 namespace. It is declared in the `` header file. This constructor initializes a new instance of the parser without any arguments. ```cpp parser(); ``` -------------------------------- ### Handling Pushes and Basic Requests in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Demonstrates how to construct a request object in C++ and push commands like PING, SUBSCRIBE, and QUIT. Commands such as SUBSCRIBE that do not have a response tuple should not be included in the response object. ```cpp request req; req.push("PING"); req.push("SUBSCRIBE", "channel"); req.push("QUIT"); ``` -------------------------------- ### Get Consumed Bytes - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/resp3/parser/get_consumed Retrieves the total number of bytes that have been successfully parsed by the resp3 parser. This is useful for tracking parsing progress and determining the exact amount of data processed from an input stream. The method is `noexcept` and declared within the `` header. ```cpp std::size_t get_consumed() const noexcept; ``` -------------------------------- ### Set HELLO command priority in Redis requests (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/config/hello_with_priority The `hello_with_priority` flag, when set to `true`, ensures that HELLO commands are moved to the front of the request queue. This allows for authentication to occur before other commands are processed. It is declared in the `` header. ```cpp bool hello_with_priority = true; ``` -------------------------------- ### Boost.Redis basic_connection Constructor with Executor Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/2constructor-0c Constructs a basic_connection with a specified executor, optionally including an SSL context and a logger. The executor is used for internal I/O operations. The logger can filter messages and customize output. ```cpp explicit basic_connection( executor_type ex, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` ```cpp basic_connection( executor_type ex, logger lgr); ``` -------------------------------- ### Declare boost::redis::config::clientname (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/config/clientname This snippet shows the declaration of the clientname parameter within the boost::redis::config namespace. It is used for the HELLO command in Boost.Redis and is declared in the `` header file. The default value is "Boost.Redis". ```cpp std::string clientname = "Boost.Redis"; ``` -------------------------------- ### Include Boost.Redis Header Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/index Include this header in exactly one source file to use the Boost.Redis library. If not included in any source file, the library is treated as header-only. Linking against OpenSSL is unconditionally required. ```cpp #include ``` -------------------------------- ### Get Next Layer Reference - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/next_layer-03 Retrieves a const reference to the next layer of a boost::redis::basic_connection. This member function is deprecated and scheduled for removal in the next release. Use alternative member functions to interact with the connection instead. The function returns a reference to the underlying SSL stream object. ```cpp auto const& next_layer() const noexcept; ``` -------------------------------- ### Construct logger with level and callback Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/logger/2constructor-05 Constructs a logger instance with a specified logging level and a callback function. The callback function `fn` accepts a logging level and a string view message. Declared in ``. ```cpp logger( level l, std::function fn); ``` -------------------------------- ### Handling Redis Responses Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Explains how to handle responses from Redis commands using `boost::redis::response` for known command counts at compile-time and `boost::redis::generic_response` for dynamic counts. It also details response type mapping. ```APIDOC ## Handling Redis Responses ### Description Boost.Redis provides strategies for handling responses based on the number of commands in a request. `boost::redis::response` is used when the number of commands is known at compile-time, while `boost::redis::generic_response` is for dynamic scenarios. This section also covers mapping RESP3 types to C++ types. ### Method N/A (Object Construction and Method Calls) ### Endpoint N/A (Client-side handling) ### Parameters N/A ### Request Example ```cpp // Request with a known number of commands boost::redis::request req; req.push("PING"); req.push("INCR", "counter"); req.push("QUIT"); // Corresponding response object boost::redis::response resp; // To ignore specific responses, use boost::redis::ignore_t // response resp_with_ignore; ``` ### Response #### Success Response (200) - **response object** (object) - Contains the results of the executed Redis commands, structured according to the template parameters. #### Response Example ```cpp // Example response object for a request with multiple commands boost::redis::response< boost::redis::ignore_t, // Response to HELLO command int, // Response to RPUSH command int, // Response to HSET command std::vector,// Response to LRANGE command std::map, // Response to HGETALL command std::string // Response to QUIT command > resp; // Executing the request and reading the response // co_await conn->async_exec(req, resp); // To ignore all responses: // co_await conn->async_exec(req, boost::redis::ignore); ``` ### Data Type Mapping **Command** | **RESP3 type** | **Possible C++ type** | **Type** ---|---|---|--- `lpush` | Number | `long long`, `int`, `std::size_t`, `std::string` | Simple `lrange` | Array | `std::vector`, `std::list`, `std::array`, `std::deque` | Aggregate `set` | Simple-string, null or blob-string | `std::string`, `std::optional` | Simple/Aggregate `get` | Blob-string | `std::string`, `std::vector` | Simple `smembers` | Set | `std::vector`, `std::set`, `std::unordered_set` | Aggregate `hgetall` | Map | `std::vector`, `std::map`, `std::unordered_map` | Aggregate ``` -------------------------------- ### Boost.Redis Namespaces Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis This section details the namespaces available within the Boost.Redis library. ```APIDOC ## Namespaces ### Description Namespaces organize the types and functions within the Boost.Redis library. ### Name - `resp3` - `adapter` ``` -------------------------------- ### Get Next Layer - Const ASIO SSL Stream in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/next_layer-06 Const version of next_layer() that returns a const reference to the underlying ASIO SSL stream wrapping a TCP socket. This deprecated function provides read-only access to the transport layer. Returns asio::ssl::stream const& with noexcept guarantee. ```cpp asio::ssl::stream const& next_layer() const noexcept; ``` -------------------------------- ### Boost.Redis Types Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis This section lists and describes the various types provided by the Boost.Redis library. ```APIDOC ## Types ### Description These types represent core components and data structures used for Redis interactions. | Name | Description | |---|---| | `address` | Address of a Redis server. | | `config` | Configure parameters used by the connection classes. | | `logger` | Defines logging configuration. | | `request` | Represents a Redis request. | | `usage` | Connection usage information. | | `connection` | A basic_connection that type erases the executor. | | `basic_connection` | A SSL connection to the Redis server. | | `any_adapter` | A type‐erased reference to a response. | | `ignore_t` | Type used to ignore responses. | | `response` | Response with compile‐time size. | | `generic_response` | A generic response to a request | ``` -------------------------------- ### boost::redis::request::request Constructor Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/2constructor The `boost::redis::request::request` constructor is declared in ``. It accepts an optional `config` object to set configuration options like enabling/disabling specific features. The default configuration enables all options. ```cpp explicit request(config cfg = config{true, false, true, true}); ``` -------------------------------- ### Using boost::redis::generic_response for Flexible Parsing in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Demonstrates how to use boost::redis::generic_response to parse any Redis command response. This is useful when the exact response structure is unknown or varies, providing a pre-order traversal of the response tree. ```cpp // Receives any RESP3 simple or aggregate data type. bool co_await conn->async_exec(req, resp); ``` -------------------------------- ### Get Next Layer - Non-const ASIO SSL Stream in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/next_layer-06 Non-const version of next_layer() that returns a reference to the underlying ASIO SSL stream wrapping a TCP socket. This deprecated function provides direct access to the transport layer for advanced use cases. Returns asio::ssl::stream& with noexcept guarantee. ```cpp asio::ssl::stream& next_layer() noexcept; ``` -------------------------------- ### Create Redis Connection with Executor and SSL Context Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/2constructor-06 Constructor for boost::redis::connection that initializes a Redis connection using an executor for I/O operations, an SSL context for secure communication (defaulting to TLSv12), and optional logger configuration for message filtering and customization. The logger defaults to outputting info level and higher messages to stderr. ```cpp explicit connection( executor_type ex, asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, logger lgr = {}); ``` -------------------------------- ### C++: Handling Redis Server Pushes (Pub/Sub) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/index This C++ coroutine demonstrates how to use Boost.Redis's `async_receive` function to handle server pushes, such as Pub/Sub messages. It shows how to subscribe to a channel, continuously read incoming messages, and handle potential connection errors. ```cpp auto receiver(std::shared_ptr conn) -> net::awaitable { request req; req.push("SUBSCRIBE", "channel"); generic_response resp; conn->set_receive_response(resp); // Loop while reconnection is enabled while (conn->will_reconnect()) { // Reconnect to channels. co_await conn->async_exec(req, ignore); // Loop reading Redis pushes. for (;;) { error_code ec; co_await conn->async_receive(resp, net::redirect_error(net::use_awaitable, ec)); if (ec) break; // Connection lost, break so we can reconnect to channels. // Use the response resp in some way and then clear it. ... consume_one(resp); } } } ``` -------------------------------- ### Async Execute Redis Commands - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_exec-0e Template function that asynchronously executes Redis commands on the server. Sends a request and waits for responses from individual commands, with automatic queueing for concurrent calls. Supports per-operation cancellation and requires completion tokens with signature void f(system::error_code, std::size_t). ```cpp template< class Response = ignore_t, class CompletionToken = asio::default_completion_token_t> auto async_exec( request const& req, Response& resp = ignore, CompletionToken&& token = {}); ``` ```cpp void f(system::error_code, std::size_t); ``` -------------------------------- ### Boost.Redis Variables Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis This section describes the global variables available in the Boost.Redis library. ```APIDOC ## Variables ### Description Global variables provide access to common objects or constants. | Name | Description | |---|---| | `ignore` | Global ignore object. | ``` -------------------------------- ### boost::redis::connection::async_exec Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/async_exec-0a Asynchronously executes a Redis request and places the response into the provided adapter. ```APIDOC ## boost::redis::connection::async_exec ### Description This function calls `boost::redis::basic_connection::async_exec` to asynchronously execute a Redis request. The results are placed into the provided `any_adapter`. ### Method Async operation (details depend on `CompletionToken`) ### Endpoint N/A (This is a library function call, not a network endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed directly to the function) ### Request Example ```cpp // Example usage within a C++ context #include #include #include // Assuming 'conn' is a valid boost::redis::connection object // Assuming 'req' is a valid boost::redis::request object // Assuming 'adapter' is a valid boost::redis::any_adapter object auto fut = boost::redis::connection::async_exec(req, adapter, boost::asio::deferred); // ... handle future 'fut' ... ``` ### Response #### Success Response (CompletionToken dependent) - **(CompletionToken type)** - The result of the asynchronous operation, typically a `boost::system::error_code` or a future. #### Response Example ```cpp // Example of handling the result with a future // If async_exec returns a std::future or similar fut.then([](auto&& fut) { try { fut.get(); // Check for exceptions // Operation successful } catch (const boost::system::system_error& ec) { // Handle error } }); ``` ``` -------------------------------- ### Boost.Redis Enums Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis This section lists and describes the enumerations available in the Boost.Redis library. ```APIDOC ## Enums ### Description Enums define a set of named constants for specific error conditions and operations. | Name | Description | |---|---| | `error` | Generic errors. | | `operation` | Connection operations that can be cancelled. | ``` -------------------------------- ### Executing a Redis Request and Handling Responses Asynchronously (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Shows the asynchronous execution of a Redis request using `conn->async_exec` and how to handle the response object. It also demonstrates how to completely ignore any response from a Redis command by passing `ignore` as the response parameter. ```cpp // Assuming 'conn' is a valid connection object and 'req' is a prepared request. co_await conn->async_exec(req, resp); // To ignore the response entirely: co_await conn->async_exec(req, ignore); ``` -------------------------------- ### Declare boost::redis::config::database_index Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/config/database_index This code snippet demonstrates the declaration of `database_index`, an optional integer representing the database to be used with the `SELECT` command in Boost.Redis. It is declared in `` and defaults to 0 if not specified. ```cpp std::optional database_index = 0; ``` -------------------------------- ### Construct logger with level Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/logger/2constructor-05 Constructs a logger instance with a specified logging level. The default level is 'info'. This constructor is declared in the `` header. ```cpp logger(level l = level::info); ``` -------------------------------- ### Asynchronously Execute Redis Request (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/connection/async_exec-0a The `async_exec` function in `boost::redis::connection` allows for asynchronous execution of a Redis request. It takes a request object and an adapter to store the response, returning a completion token. Dependencies include the `` header and the Asio library for asynchronous operations. ```cpp template auto async_exec( request const& req, any_adapter adapter, CompletionToken&& token = {}); ``` -------------------------------- ### Append Command with Key and Range to Redis Request (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/push_range-001 The `push_range` function appends a Redis command to a request, accepting a command name, a key, and a range of arguments. Arguments must be convertible to `std::string_view` or support `boost_redis_to_bulk` serialization. This is useful for commands like HSET with multiple field-value pairs. ```cpp template void push_range( std::string_view cmd, std::string_view key, ForwardIterator begin, ForwardIterator end, std::iterator_traits::value_type* = nullptr); // Example Usage: std::map map { {"key1", "value1"} , {"key2", "value2"} , {"key3", "value3"} }; request req; req.push_range("HSET", "key", map.cbegin(), map.cend()); ``` -------------------------------- ### Representing a Redis Request Pipeline Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request The boost::redis::request class represents a sequence of Redis commands, akin to a pipeline. It is declared in ``. This class manages the internal storage and provides methods to append commands. ```cpp class request; ``` -------------------------------- ### Asynchronous Redis Command Execution using boost::redis Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/basic_connection/async_exec-02 Executes a request on the Redis server asynchronously. It waits for responses for each command and queues concurrent calls. The completion token must have a specific signature: void f(system::error_code, std::size_t). Per-operation cancellation is supported, and both the request and adapter object must remain alive until completion. ```cpp template> auto async_exec( request const& req, any_adapter adapter, CompletionToken&& token = {}); ``` ```cpp void f(system::error_code, std::size_t); ``` -------------------------------- ### Defining Response Objects for Redis Requests (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Illustrates how to declare `boost::redis::response` objects to match the expected structure of Redis responses. It shows how to specify types for each command's reply when the number of commands is known at compile-time, and how to use `boost::redis::ignore_t` to skip specific responses. ```cpp request req; req.push("PING"); req.push("INCR", "key"); req.push("QUIT"); // Response object matching the three commands. response // Ignore the second and last responses. response ``` -------------------------------- ### boost::redis::usage Struct Definition Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/usage Defines the structure for tracking Redis connection usage statistics. This includes counts for commands sent, bytes sent, responses received, and pushes received, along with associated byte counts. ```cpp #include struct usage; ``` -------------------------------- ### General Response Handling with boost::redis::resp3::node in C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/requests_responses Introduces boost::redis::resp3::node for handling complex or unpredictable Redis response structures, such as those with dynamic types or nested aggregates. This provides a general abstraction for any RESP3 data. ```cpp template struct basic_node { // The RESP3 type of the data in this node. type data_type; // The number of elements of an aggregate (or 1 for simple data). std::size_t aggregate_size; // The depth of this node in the response tree. std::size_t depth; // The actual data. For aggregate types this is always empty. String value; }; ``` -------------------------------- ### Redis Request Config Data Members - C++ Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/request/config Configuration options for boost::redis::request::config struct controlling async_exec behavior. Includes cancel_on_connection_lost (bool) to cancel pending requests if connection drops before sending, cancel_if_not_connected (bool) to fail requests made before connection establishment, cancel_if_unresponded (bool) to prevent automatic cancellation of sent but unanswered requests, and hello_with_priority (bool) to prioritize HELLO commands in the request queue. ```cpp bool cancel_on_connection_lost; // Cancel async_exec if connection lost before request sent bool cancel_if_not_connected; // Complete with error::not_connected if called before Redis connection established bool cancel_if_unresponded; // If false, don't auto-cancel requests written to socket but unanswered when async_run completes bool hello_with_priority; // If true, move HELLO commands to front of request queue for early authentication ``` -------------------------------- ### Initialize commands_sent Counter (C++) Source: https://www.boost.org/doc/libs/latest/libs/redis/doc/html/redis/reference/boost/redis/usage/commands_sent This C++ code snippet demonstrates the declaration and initialization of the `commands_sent` counter, which is part of the `boost::redis::usage` class. It is used to keep track of the total number of commands sent to the Redis server. No external dependencies are required for this specific declaration. ```cpp std::size_t commands_sent = 0; ```