Loading...
Searching...
No Matches
cpp20_intro.cpp
1/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#include <boost/redis/connection.hpp>
8
9#include <boost/asio/co_spawn.hpp>
10#include <boost/asio/consign.hpp>
11#include <boost/asio/detached.hpp>
12
13#include <iostream>
14
15#if defined(BOOST_ASIO_HAS_CO_AWAIT)
16
17namespace asio = boost::asio;
22
23// Called from the main function (see main.cpp)
24auto co_main(config cfg) -> asio::awaitable<void>
25{
26 auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
27 conn->async_run(cfg, asio::consign(asio::detached, conn));
28
29 // A request containing only a ping command.
30 request req;
31 req.push("PING", "Hello world");
32
33 // Response where the PONG response will be stored.
34 response<std::string> resp;
35
36 // Executes the request.
37 co_await conn->async_exec(req, resp);
38 conn->cancel();
39
40 std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
41}
42
43#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
A basic_connection that type erases the executor.
Creates Redis requests.
Definition request.hpp:46
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Definition response.hpp:25
Configure parameters used by the connection classes.
Definition config.hpp:30