7#include <boost/redis/connection.hpp>
8#include <boost/redis/resp3/serialization.hpp>
10#include <boost/asio/co_spawn.hpp>
11#include <boost/asio/consign.hpp>
12#include <boost/asio/detached.hpp>
13#include <boost/system/errc.hpp>
21#if defined(BOOST_ASIO_HAS_CO_AWAIT)
23namespace asio = boost::asio;
24namespace resp3 = boost::redis::resp3;
34using tutorial::person;
42void boost_redis_to_bulk(std::string& to, person
const& u)
45 if (!u.SerializeToString(&tmp))
48 resp3::boost_redis_to_bulk(to, tmp);
51void boost_redis_from_bulk(person& u, node_view
const& node, boost::system::error_code& ec)
53 std::string
const tmp{
node.value};
54 if (!u.ParseFromString(tmp))
60using tutorial::boost_redis_to_bulk;
61using tutorial::boost_redis_from_bulk;
63asio::awaitable<void> co_main(config cfg)
65 auto ex =
co_await asio::this_coro::executor;
66 auto conn = std::make_shared<connection>(ex);
67 conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
72 p.set_email(
"No email yet.");
75 req.push(
"SET",
"protobuf-key", p);
76 req.push(
"GET",
"protobuf-key");
78 response<ignore_t, person> resp;
81 co_await conn->async_exec(req, resp);
84 std::cout <<
"Name: " << std::get<1>(resp).value().name() <<
"\n"
85 <<
"Age: " << std::get<1>(resp).value().id() <<
"\n"
86 <<
"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.
basic_node< std::string > node
A node in the response tree that owns its data.
operation
Connection operations that can be cancelled.
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
@ invalid_data_type
Invalid RESP3 type.
Configure parameters used by the connection classes.
A node in the response tree.