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 asio = boost::asio;
22using namespace std::chrono_literals;
25using boost::redis::consume_one;
30using boost::system::error_code;
32using signal_set = asio::deferred_t::as_default_on_t<asio::signal_set>;
52receiver(std::shared_ptr<connection> conn) -> asio::awaitable<void>
55 req.push(
"SUBSCRIBE",
"channel");
58 conn->set_receive_response(resp);
61 while (conn->will_reconnect()) {
64 co_await conn->async_exec(req, ignore, asio::deferred);
67 for (error_code ec;;) {
70 if (ec == error::sync_receive_push_failed) {
72 co_await conn->async_receive(asio::redirect_error(asio::use_awaitable, ec));
79 << resp.value().at(1).value
80 <<
" " << resp.value().at(2).value
81 <<
" " << resp.value().at(3).value
89auto co_main(config cfg) -> asio::awaitable<void>
91 auto ex =
co_await asio::this_coro::executor;
92 auto conn = std::make_shared<connection>(ex);
93 asio::co_spawn(ex, receiver(conn), asio::detached);
94 conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
96 signal_set sig_set(ex, SIGINT, SIGTERM);
97 co_await sig_set.async_wait();
A basic_connection that type erases the executor.
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.