13 #include <boost/json.hpp>
14 #include <boost/json/src.hpp>
19 #include <aedis/src.hpp>
21 namespace net = boost::asio;
25 using namespace boost::json;
33 void tag_invoke(value_from_tag, value& jv, user
const& u)
38 , {
"country", u.country}
43 void extract(
object const& obj, T& t, boost::string_view key)
45 t = value_to<T>(obj.at(key));
48 user tag_invoke(value_to_tag<user>, value
const& jv)
51 object const& obj = jv.as_object();
52 extract(obj, u.name,
"name");
53 extract(obj, u.age,
"age");
54 extract(obj, u.country,
"country");
59 void to_bulk(std::string& to, user
const& u)
61 aedis::resp3::to_bulk(to, serialize(value_from(u)));
65 void from_bulk(user& u, boost::string_view sv, boost::system::error_code&)
68 u = value_to<user>(jv);
71 std::ostream&
operator<<(std::ostream& os, user
const& u)
73 os <<
"Name: " << u.name <<
"\n"
74 <<
"Age: " << u.age <<
"\n"
75 <<
"Country: " << u.country;
80 bool operator<(user
const& a, user
const& b)
82 return std::tie(a.name, a.age, a.country) < std::tie(b.name, b.age, b.country);
91 {{
"Joao",
"58",
"Brazil"} , {
"Serge",
"60",
"France"}};
96 req.
push(
"SMEMBERS",
"sadd-key");
99 std::tuple<aedis::ignore, int, std::set<user>, std::string> resp;
101 db.async_run(req,
adapt(resp), [](
auto ec,
auto) {
102 std::cout << ec.message() << std::endl;
108 print(std::get<2>(resp));
A high level connection to Redis.
void push_range(boost::string_view cmd, Key const &key, Range const &range)
Appends a new command to the end of the request.
void push(boost::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
std::ostream & operator<<(std::ostream &os, type t)
Writes the type to the output stream.
auto adapt() noexcept
Creates an adapter that ignores responses.