Boost.Redis 1.4.2
A redis client library
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#include <boost/asio/deferred.hpp>
9#include <boost/asio/co_spawn.hpp>
10#include <boost/asio/detached.hpp>
11#include <boost/asio/consign.hpp>
12#include <iostream>
13
14#if defined(BOOST_ASIO_HAS_CO_AWAIT)
15
16namespace asio = boost::asio;
21
22// Called from the main function (see main.cpp)
23auto co_main(config cfg) -> asio::awaitable<void>
24{
25 auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
26 conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
27
28 // A request containing only a ping command.
29 request req;
30 req.push("PING", "Hello world");
31
32 // Response where the PONG response will be stored.
33 response<std::string> resp;
34
35 // Executes the request.
36 co_await conn->async_exec(req, resp, asio::deferred);
37 conn->cancel();
38
39 std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
40}
41
42#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
A basic_connection that type erases the executor.
Definition: connection.hpp:337
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