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-06 18:03:04 +01:00
parent 3fbd8b668f
commit 49965d215a
5 changed files with 197 additions and 92 deletions

49
examples/basic1.cpp Normal file
View File

@@ -0,0 +1,49 @@
/* Copyright (c) 2019 - 2021 Marcelo Zimbres Silva (mzimbres at gmail dot com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <iostream>
#include <aedis/aedis.hpp>
#include "types.hpp"
#include "utils.ipp"
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.
*
* Notice the responses are read in the same object for
* simplification.
*/
net::awaitable<void> ping()
{
auto socket = co_await make_connection();
resp3::stream<tcp_socket> stream{std::move(socket)};
resp3::request req;
req.push(command::hello, 3);
req.push(command::ping);
req.push(command::quit);
co_await stream.async_write(req);
resp3::response resp;
co_await stream.async_read(resp);
co_await stream.async_read(resp);
co_await stream.async_read(resp);
std::cout << resp << std::endl;
}
int main()
{
net::io_context ioc;
co_spawn(ioc, ping(), net::detached);
ioc.run();
}