7#include <boost/asio.hpp>
8#if defined(BOOST_ASIO_HAS_CO_AWAIT)
9#include <boost/asio/experimental/awaitable_operators.hpp>
10#define BOOST_JSON_NO_LIB
11#define BOOST_CONTAINER_NO_LIB
12#include <boost/json.hpp>
20#include "common/common.hpp"
23#include <boost/json/src.hpp>
25namespace net = boost::asio;
26namespace resp3 = aedis::resp3;
27using namespace net::experimental::awaitable_operators;
28using namespace boost::json;
36 friend auto operator<(user
const& a, user
const& b)
38 return std::tie(a.name, a.age, a.country) < std::tie(b.name, b.age, b.country);
41 friend auto operator<<(std::ostream& os, user
const& u) -> std::ostream&
43 os <<
"Name: " << u.name <<
"\n"
44 <<
"Age: " << u.age <<
"\n"
45 <<
"Country: " << u.country;
52void tag_invoke(value_from_tag, value& jv, user
const& u)
57 , {
"country", u.country}
62void extract(
object const& obj, T& t, std::string_view key)
64 t = value_to<T>(obj.at(key));
67auto tag_invoke(value_to_tag<user>, value
const& jv)
70 object const& obj = jv.as_object();
71 extract(obj, u.name,
"name");
72 extract(obj, u.age,
"age");
73 extract(obj, u.country,
"country");
78void to_bulk(std::pmr::string& to, user
const& u)
80 aedis::resp3::to_bulk(to, serialize(value_from(u)));
83void from_bulk(user& u, std::string_view sv, boost::system::error_code&)
86 u = value_to<user>(jv);
89net::awaitable<void> co_main(std::string host, std::string port)
92 {{
"Joao",
"58",
"Brazil"} , {
"Serge",
"60",
"France"}};
97 req.
push(
"SMEMBERS",
"sadd-key");
100 std::tuple<aedis::ignore, int, std::set<user>, std::string> resp;
102 auto conn = std::make_shared<connection>(
co_await net::this_coro::executor);
104 co_await connect(conn, host, port);
105 co_await (conn->async_run() || conn->async_exec(req,
adapt(resp)));
107 for (
auto const& e: std::get<2>(resp))
108 std::cout << e <<
"\n";
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
void to_bulk(Request &to, std::string_view data)
Adds a bulk to the request.
void push_range(std::string_view cmd, Key const &key, ForwardIterator begin, ForwardIterator end, typename std::iterator_traits< ForwardIterator >::value_type *=nullptr)
Appends a new command to the end of the request.
auto operator<<(std::ostream &os, type t) -> std::ostream &
Writes the type to the output stream.
auto adapt(std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)()) noexcept
Creates an adapter that ignores responses.