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#define BOOST_JSON_NO_LIB
19#define BOOST_CONTAINER_NO_LIB
20#include <boost/json/serialize.hpp>
21#include <boost/json/parse.hpp>
22#include <boost/json/value_from.hpp>
23#include <boost/redis/resp3/serialization.hpp>
24#include <boost/json/src.hpp>
26namespace net = boost::asio;
27using namespace boost::describe;
42BOOST_DESCRIBE_STRUCT(user, (), (name, age, country))
46 { boost::redis::resp3::boost_redis_to_bulk(to, boost::json::serialize(boost::json::value_from(u))); }
48void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
49 { u = boost::json::value_to<user>(boost::json::parse(sv)); }
51auto co_main(config cfg) -> net::awaitable<void>
53 auto ex =
co_await net::this_coro::executor;
54 auto conn = std::make_shared<connection>(ex);
55 conn->async_run(cfg, {}, net::consign(net::detached, conn));
58 user
const u{
"Joao",
"58",
"Brazil"};
62 req.push(
"SET",
"json-key", u);
63 req.push(
"GET",
"json-key");
65 response<ignore_t, user> resp;
67 co_await conn->async_exec(req, resp, net::deferred);
72 <<
"Name: " << std::get<1>(resp).value().name <<
"\n"
73 <<
"Age: " << std::get<1>(resp).value().age <<
"\n"
74 <<
"Country: " << std::get<1>(resp).value().country <<
"\n";
A basic_connection that type erases the executor.
void boost_redis_to_bulk(std::string &payload, std::string_view data)
Adds a bulk to the request.
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.