Aedis 1.3.1  
A redis client designed for performance and scalability
low_level_sync.cpp
1/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#include <string>
8#include <iostream>
9
10#include <boost/asio/connect.hpp>
11
12#include <aedis.hpp>
13#include <aedis/src.hpp>
14
15namespace net = boost::asio;
16namespace resp3 = aedis::resp3;
17
20using net::ip::tcp;
21
22int main()
23{
24 try {
25 net::io_context ioc;
26 tcp::resolver resv{ioc};
27 auto const res = resv.resolve("127.0.0.1", "6379");
28 tcp::socket socket{ioc};
29 net::connect(socket, res);
30
31 // Creates the request and writes to the socket.
32 request req;
33 req.push("HELLO", 3);
34 req.push("PING", "Hello world");
35 req.push("QUIT");
36 resp3::write(socket, req);
37
38 // Responses
39 std::string buffer, resp;
40
41 // Reads the responses to all commands in the request.
42 auto dbuffer = net::dynamic_buffer(buffer);
43 resp3::read(socket, dbuffer);
44 resp3::read(socket, dbuffer, adapt2(resp));
45 resp3::read(socket, dbuffer);
46
47 std::cout << "Ping: " << resp << std::endl;
48
49 } catch (std::exception const& e) {
50 std::cerr << e.what() << std::endl;
51 exit(EXIT_FAILURE);
52 }
53}
Creates Redis requests.
Definition: request.hpp:176
void push(boost::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
Definition: request.hpp:265
auto adapt2() noexcept
Creates a dummy response adapter.
Definition: adapt.hpp:40
auto write(SyncWriteStream &stream, Request const &req)
Writes a request synchronously.
Definition: write.hpp:24
auto read(SyncReadStream &stream, DynamicBuffer buf, ResponseAdapter adapter, boost::system::error_code &ec) -> std::size_t
Reads a complete response to a command sychronously.
Definition: read.hpp:56