2
0
mirror of https://github.com/boostorg/redis.git synced 2026-02-22 03:32:22 +00:00

Improvements in the examples.

This commit is contained in:
Marcelo Zimbres
2021-11-13 12:48:18 +01:00
parent 3b221c4935
commit 381cc0b4f3
17 changed files with 224 additions and 299 deletions

View File

@@ -15,30 +15,44 @@
using namespace aedis;
/* A very simple example to illustrate the basic principles. It adds
* three commands to the request and reads the response one after the
* other.
/** A simple example that illustrates the basic principles. Three commands are
* sent in the same request
*
* Notice the responses are read in the same object for
* simplification.
* 1. hello (always required)
* 2. ping
* 3. quit
*
* The responses are then read in sequence. For simplification we read all
* responses on the same object.
*/
net::awaitable<void> ping()
{
auto socket = co_await make_connection();
try {
resp3::request req;
req.push(command::hello, 3);
req.push(command::ping);
req.push(command::quit);
resp3::request req;
req.push(command::hello, 3);
req.push(command::ping);
req.push(command::quit);
co_await async_write(socket, req);
auto socket = co_await make_connection();
co_await async_write(socket, req);
std::string buffer;
resp3::response resp;
co_await async_read(socket, buffer, resp);
co_await async_read(socket, buffer, resp);
co_await async_read(socket, buffer, resp);
std::string buffer;
resp3::response resp;
std::cout << resp << std::endl;
// hello
co_await async_read(socket, buffer, resp);
// ping
co_await async_read(socket, buffer, resp);
// quit
co_await async_read(socket, buffer, resp);
std::cout << resp << std::endl;
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
}
}
int main()