7#include <boost/redis/connection.hpp>
8#include <boost/asio/deferred.hpp>
9#include <boost/asio/detached.hpp>
10#include <boost/describe.hpp>
11#include <boost/asio/consign.hpp>
12#include <boost/asio/use_awaitable.hpp>
16#if defined(BOOST_ASIO_HAS_CO_AWAIT)
18#include <boost/json/serialize.hpp>
19#include <boost/json/parse.hpp>
20#include <boost/json/value_from.hpp>
21#include <boost/json/value_to.hpp>
22#include <boost/redis/resp3/serialization.hpp>
24namespace asio = boost::asio;
25using namespace boost::describe;
40BOOST_DESCRIBE_STRUCT(user, (), (name, age, country))
43void boost_redis_to_bulk(std::string& to, user
const& u)
44 { boost::redis::resp3::boost_redis_to_bulk(to, boost::json::serialize(boost::json::value_from(u))); }
46void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
47 { u = boost::json::value_to<user>(boost::json::parse(sv)); }
49auto co_main(config cfg) -> asio::awaitable<void>
51 auto ex =
co_await asio::this_coro::executor;
52 auto conn = std::make_shared<connection>(ex);
53 conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
56 user
const u{
"Joao",
"58",
"Brazil"};
60 req.push(
"SET",
"json-key", u);
61 req.push(
"GET",
"json-key");
63 response<ignore_t, user> resp;
65 co_await conn->async_exec(req, resp, asio::deferred);
70 <<
"Name: " << std::get<1>(resp).value().name <<
"\n"
71 <<
"Age: " << std::get<1>(resp).value().age <<
"\n"
72 <<
"Country: " << std::get<1>(resp).value().country <<
"\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.
Configure parameters used by the connection classes.