2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

Missing files.

This commit is contained in:
Marcelo Zimbres
2022-02-07 09:31:41 +01:00
parent fe3cc2efb0
commit 317690ee91
3 changed files with 2717 additions and 0 deletions

2565
doc/Doxyfile.in Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
/* Copyright (c) 2019 Marcelo Zimbres Silva (mzimbres@gmail.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 <memory>
#include <aedis/aedis.hpp>
#include <aedis/src.hpp>
#include "lib/net_utils.hpp"
namespace net = aedis::net;
using aedis::redis::command;
using aedis::resp3::experimental::client;
using aedis::resp3::node;
using aedis::resp3::type;
net::awaitable<void> connection_manager(std::shared_ptr<client> db)
{
try {
auto socket = co_await connect();
co_await db->engage(std::move(socket));
} catch (std::exception const& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
int main()
{
try {
std::vector<node> resps;
auto on_msg = [&resps](std::error_code ec, command cmd)
{
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
return;
}
std::cout << cmd << ":: " << resps.front().data << std::endl;
resps.clear();
};
net::io_context ioc{1};
// This adapter uses the general response that is suitable for
// all commands, so the command parameter will be ignored.
auto ext_adapter = [adapter = adapt(resps)](command, type t, std::size_t aggregate_size, std::size_t depth, char const* data, std::size_t size, std::error_code& ec) mutable
{ return adapter(t, aggregate_size, depth, data, size, ec); };
auto db = std::make_shared<client>(ioc.get_executor());
db->set_extended_adapter(ext_adapter);
db->set_msg_callback(on_msg);
net::co_spawn(ioc, connection_manager(db), net::detached);
db->send(command::ping, "O rato roeu a roupa do rei de Roma");
db->send(command::incr, "redis-client-counter");
db->send(command::quit);
ioc.run();
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
exit(EXIT_FAILURE);
}
}

View File

@@ -0,0 +1,83 @@
/* Copyright (c) 2019 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 <vector>
#include <tuple>
#include <array>
#include <aedis/aedis.hpp>
#include <aedis/src.hpp>
#include "lib/net_utils.hpp"
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using resp3::adapt;
using resp3::node;
namespace net = aedis::net;
using net::async_write;
using net::buffer;
using net::dynamic_buffer;
// The response to some commands can't be transalated into C++ data
// structures like \c std::string or STL containers, A multipurpose
// response is provided for such cases.
net::awaitable<void> multipurpose_response()
{
try {
auto socket = co_await connect();
auto list = {"one", "two", "three"};
std::string request;
auto sr = make_serializer(request);
sr.push(command::hello, 3);
sr.push(command::flushall);
sr.push(command::multi);
sr.push(command::ping, "Some message");
sr.push(command::incr, "incr-key");
sr.push_range(command::rpush, "list-key", std::cbegin(list), std::cend(list));
sr.push(command::lrange, "list-key", 0, -1);
sr.push(command::exec);
sr.push(command::quit);
co_await async_write(socket, buffer(request));
// Expected responses.
std::vector<node> exec;
// Reads the response.
std::string buffer;
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // hello
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // flushall
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // multi
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // ping
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // incr
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // rpush
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // lrange
co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(exec));
co_await resp3::async_read(socket, dynamic_buffer(buffer)); // quit
// Prints the response.
std::cout << "General format:\n";
for (auto const& e: exec) std::cout << e << "\n";
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
exit(EXIT_FAILURE);
}
}
int main()
{
net::io_context ioc;
co_spawn(ioc, multipurpose_response(), net::detached);
ioc.run();
}