7#include <boost/redis/connection.hpp>
8#include <boost/asio/use_awaitable.hpp>
9#include <boost/asio/redirect_error.hpp>
10#include <boost/asio/detached.hpp>
13#if defined(BOOST_ASIO_HAS_CO_AWAIT)
15namespace net = boost::asio;
16using endpoints = net::ip::tcp::resolver::results_type;
24auto redir(boost::system::error_code& ec)
25 {
return net::redirect_error(net::use_awaitable, ec); }
30auto resolve_master_address(std::vector<address>
const& addresses) -> net::awaitable<address>
33 req.push(
"SENTINEL",
"get-master-addr-by-name",
"mymaster");
36 auto conn = std::make_shared<connection>(
co_await net::this_coro::executor);
38 response<std::optional<std::array<std::string, 2>>,
ignore_t> resp;
39 for (
auto addr : addresses) {
40 boost::system::error_code ec;
46 conn->async_run(cfg, {}, net::consign(net::detached, conn));
47 co_await conn->async_exec(req, resp, redir(ec));
50 if (!ec && std::get<0>(resp))
51 co_return address{std::get<0>(resp).value().value().at(0), std::get<0>(resp).value().value().at(1)};
57auto co_main(config cfg) -> net::awaitable<void>
61 std::vector<address>
const addresses
62 { address{
"foo",
"26379"}
63 , address{
"bar",
"26379"}
67 auto const ep =
co_await resolve_master_address(addresses);
70 <<
"Host: " << ep.host <<
"\n"
71 <<
"Port: " << ep.port <<
"\n"
A basic_connection that type erases the executor.
std::decay_t< decltype(std::ignore)> ignore_t
Type used to ignore responses.
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Address of a Redis server.
Configure parameters used by the connection classes.