7#include <boost/redis/connection.hpp>
8#include <boost/redis/logger.hpp>
9#include <boost/asio/awaitable.hpp>
10#include <boost/asio/use_awaitable.hpp>
11#include <boost/asio/deferred.hpp>
12#include <boost/asio/co_spawn.hpp>
13#include <boost/asio/detached.hpp>
14#include <boost/asio/consign.hpp>
15#include <boost/asio/redirect_error.hpp>
16#include <boost/asio/signal_set.hpp>
19#if defined(BOOST_ASIO_HAS_CO_AWAIT)
21namespace net = boost::asio;
22using namespace std::chrono_literals;
28using boost::system::error_code;
30using signal_set = net::deferred_t::as_default_on_t<net::signal_set>;
50receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
53 req.push(
"SUBSCRIBE",
"channel");
56 while (conn->will_reconnect()) {
64 co_await conn->async_receive(resp, net::redirect_error(net::use_awaitable, ec));
68 << resp.value().at(1).value
69 <<
" " << resp.value().at(2).value
70 <<
" " << resp.value().at(3).value
77auto co_main(config cfg) -> net::awaitable<void>
79 auto ex =
co_await net::this_coro::executor;
80 auto conn = std::make_shared<connection>(ex);
81 net::co_spawn(ex, receiver(conn), net::detached);
82 conn->async_run(cfg, {}, net::consign(net::detached, conn));
84 signal_set sig_set(ex, SIGINT, SIGTERM);
85 co_await sig_set.async_wait();
A basic_connection that type erases the executor.
auto async_exec(request const &req, Response &resp, CompletionToken token)
Calls boost::redis::basic_connection::async_exec.
ignore_t ignore
Global ignore object.
adapter::result< std::vector< resp3::node > > generic_response
A generic response to a request.
Configure parameters used by the connection classes.