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 <boost/asio/signal_set.hpp>
13#include <boost/asio/awaitable.hpp>
16#if defined(BOOST_ASIO_HAS_CO_AWAIT)
23namespace net = boost::asio;
29using signal_set = net::deferred_t::as_default_on_t<net::signal_set>;
31auto stream_reader(std::shared_ptr<connection> conn) -> net::awaitable<void>
33 std::string redisStreamKey_;
37 std::string stream_id{
"$"};
38 std::string
const field =
"myfield";
41 req.push(
"XREAD",
"BLOCK",
"0",
"STREAMS",
"test-topic", stream_id);
42 co_await conn->async_exec(req, resp, net::deferred);
58 std::size_t item_index = 0;
59 while (item_index < std::size(resp.value())) {
60 auto const& val = resp.value().at(item_index).value;
62 if (field.compare(val) == 0) {
66 stream_id = resp.value().at(item_index - 2).value;
68 <<
"StreamId: " << stream_id <<
", "
69 <<
"MyField: " << resp.value().at(item_index + 1).value
84auto co_main(config cfg) -> net::awaitable<void>
86 auto ex =
co_await net::this_coro::executor;
87 auto conn = std::make_shared<connection>(ex);
88 net::co_spawn(ex, stream_reader(conn), net::detached);
91 cfg.health_check_interval = std::chrono::seconds::zero();
92 conn->async_run(cfg, {}, net::consign(net::detached, conn));
94 signal_set sig_set(ex, SIGINT, SIGTERM);
95 co_await sig_set.async_wait();
A basic_connection that type erases the executor.
adapter::result< std::vector< resp3::node > > generic_response
A generic response to a request.
operation
Connection operations that can be cancelled.
Configure parameters used by the connection classes.