7#include <boost/redis/connection.hpp>
8#include <boost/redis/resp3/serialization.hpp>
9#include <boost/asio/deferred.hpp>
10#include <boost/asio/co_spawn.hpp>
11#include <boost/asio/detached.hpp>
12#include <boost/asio/consign.hpp>
13#include <boost/system/errc.hpp>
20#if defined(BOOST_ASIO_HAS_CO_AWAIT)
22namespace net = boost::asio;
31using tutorial::person;
40void boost_redis_to_bulk(std::string& to, person
const& u)
43 if (!u.SerializeToString(&tmp))
46 boost::redis::resp3::boost_redis_to_bulk(to, tmp);
49void boost_redis_from_bulk(person& u, std::string_view sv, boost::system::error_code& ec)
51 std::string
const tmp {sv};
52 if (!u.ParseFromString(tmp))
58using tutorial::boost_redis_to_bulk;
59using tutorial::boost_redis_from_bulk;
61net::awaitable<void> co_main(config cfg)
63 auto ex =
co_await net::this_coro::executor;
64 auto conn = std::make_shared<connection>(ex);
65 conn->async_run(cfg, {}, net::consign(net::detached, conn));
70 p.set_email(
"No email yet.");
73 req.push(
"SET",
"protobuf-key", p);
74 req.push(
"GET",
"protobuf-key");
76 response<ignore_t, person> resp;
79 co_await conn->async_exec(req, resp, net::deferred);
83 <<
"Name: " << std::get<1>(resp).value().name() <<
"\n"
84 <<
"Age: " << std::get<1>(resp).value().id() <<
"\n"
85 <<
"Email: " << std::get<1>(resp).value().email() <<
"\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.
operation
Connection operations that can be cancelled.
@ invalid_data_type
Invalid RESP3 type.
Configure parameters used by the connection classes.