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

Improvements in the project structure.

This commit is contained in:
Marcelo Zimbres
2022-06-06 10:42:53 +02:00
parent a40c9fe35f
commit 97cb5b5b25
20 changed files with 66 additions and 212 deletions

View File

@@ -55,11 +55,11 @@ nobase_include_HEADERS =\
$(top_srcdir)/aedis/error.hpp\
$(top_srcdir)/aedis/impl/error.ipp\
$(top_srcdir)/aedis/detail/net.hpp\
$(top_srcdir)/aedis/redis/command.hpp\
$(top_srcdir)/aedis/generic/connection.hpp\
$(top_srcdir)/aedis/generic/adapt.hpp\
$(top_srcdir)/aedis/generic/detail/connection_ops.hpp\
$(top_srcdir)/aedis/sentinel/command.hpp\
$(top_srcdir)/aedis/command.hpp\
$(top_srcdir)/aedis/impl/command.ipp\
$(top_srcdir)/aedis/connection.hpp\
$(top_srcdir)/aedis/adapt.hpp\
$(top_srcdir)/aedis/detail/connection_ops.hpp\
$(top_srcdir)/aedis/aedis.hpp\
$(top_srcdir)/aedis/adapter/detail/adapters.hpp\
$(top_srcdir)/aedis/adapter/error.hpp\
@@ -77,8 +77,6 @@ nobase_include_HEADERS =\
$(top_srcdir)/aedis/resp3/exec.hpp\
$(top_srcdir)/aedis/resp3/write.hpp\
$(top_srcdir)/aedis/resp3/request.hpp\
$(top_srcdir)/aedis/redis/impl/command.ipp\
$(top_srcdir)/aedis/sentinel/impl/command.ipp\
$(top_srcdir)/aedis/resp3/detail/impl/parser.ipp\
$(top_srcdir)/aedis/resp3/impl/type.ipp

View File

@@ -4,8 +4,8 @@
* accompanying file LICENSE.txt)
*/
#ifndef AEDIS_GENERIC_ADAPT_HPP
#define AEDIS_GENERIC_ADAPT_HPP
#ifndef AEDIS_ADAPT_HPP
#define AEDIS_ADAPT_HPP
#include <tuple>
@@ -19,7 +19,6 @@
#include <aedis/adapter/detail/response_traits.hpp>
namespace aedis {
namespace generic {
namespace detail {
struct ignore_adapter {
@@ -128,7 +127,6 @@ auto adapt(T& t) noexcept
return detail::response_traits<T>::adapt(t);
}
} // generic
} // aedis
#endif // AEDIS_GENERIC_ADAPT_HPP
#endif // AEDIS_ADAPT_HPP

View File

@@ -8,16 +8,15 @@
#define AEDIS_HPP
#include <aedis/error.hpp>
#include <aedis/command.hpp>
#include <aedis/adapt.hpp>
#include <aedis/connection.hpp>
#include <aedis/resp3/read.hpp>
#include <aedis/resp3/write.hpp>
#include <aedis/resp3/exec.hpp>
#include <aedis/resp3/request.hpp>
#include <aedis/adapter/adapt.hpp>
#include <aedis/adapter/error.hpp>
#include <aedis/redis/command.hpp>
#include <aedis/sentinel/command.hpp>
#include <aedis/generic/connection.hpp>
#include <aedis/generic/adapt.hpp>
/** \mainpage Documentation
\tableofcontents

View File

@@ -4,14 +4,13 @@
* accompanying file LICENSE.txt)
*/
#ifndef AEDIS_REDIS_COMMAND_HPP
#define AEDIS_REDIS_COMMAND_HPP
#ifndef AEDIS_COMMAND_HPP
#define AEDIS_COMMAND_HPP
#include <ostream>
#include <string>
namespace aedis {
namespace redis {
/** \brief Redis commands.
* \ingroup any
@@ -285,6 +284,8 @@ enum class command {
sdiffstore,
/// https://redis.io/commands/select
select,
/// https://redis.io/topics/sentinel
sentinel,
/// https://redis.io/commands/set
set,
/// https://redis.io/commands/setbit
@@ -451,7 +452,6 @@ std::ostream& operator<<(std::ostream& os, command c);
// Checks whether a command has push response.
bool has_push_response(command cmd);
} // redis
} // aedis
#endif // AEDIS_REDIS_COMMAND_HPP
#endif // AEDIS_COMMAND_HPP

View File

@@ -4,8 +4,8 @@
* accompanying file LICENSE.txt)
*/
#ifndef AEDIS_GENERIC_CONNECTION_HPP
#define AEDIS_GENERIC_CONNECTION_HPP
#ifndef AEDIS_CONNECTION_HPP
#define AEDIS_CONNECTION_HPP
#include <vector>
#include <queue>
@@ -17,12 +17,11 @@
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/steady_timer.hpp>
#include <aedis/adapt.hpp>
#include <aedis/resp3/request.hpp>
#include <aedis/generic/adapt.hpp>
#include <aedis/generic/detail/connection_ops.hpp>
#include <aedis/detail/connection_ops.hpp>
namespace aedis {
namespace generic {
/** \brief A high level Redis connection.
* \ingroup any
@@ -119,7 +118,7 @@ public:
* @li Starts the idle check operation with the timeout of twice
* the value of connection::config::ping_interval. If no data is
* received during that time interval \c async_run completes with
* generic::error::idle_timeout.
* error::idle_timeout.
*
* @li Starts the healthy check operation that sends
* redis::command::ping to Redis with a frequency equal to
@@ -181,7 +180,7 @@ public:
class CompletionToken = default_completion_token_type>
auto async_exec(
request_type const& req,
Adapter adapter = generic::adapt(),
Adapter adapter = aedis::adapt(),
CompletionToken token = CompletionToken{})
{
return boost::asio::async_compose
@@ -197,7 +196,7 @@ public:
class CompletionToken = default_completion_token_type>
auto
async_read_push(
Adapter adapter = generic::adapt(),
Adapter adapter = aedis::adapt(),
CompletionToken token = CompletionToken{})
{
return boost::asio::async_compose
@@ -407,7 +406,6 @@ private:
request_type req_;
};
} // generic
} // aedis
#endif // AEDIS_GENERIC_CONNECTION_HPP
#endif // AEDIS_CONNECTION_HPP

View File

@@ -4,8 +4,8 @@
* accompanying file LICENSE.txt)
*/
#ifndef AEDIS_GENERIC_CONNECTION_OPS_HPP
#define AEDIS_GENERIC_CONNECTION_OPS_HPP
#ifndef AEDIS_CONNECTION_OPS_HPP
#define AEDIS_CONNECTION_OPS_HPP
#include <array>
@@ -15,6 +15,7 @@
#include <boost/core/ignore_unused.hpp>
#include <boost/asio/experimental/parallel_group.hpp>
#include <aedis/adapt.hpp>
#include <aedis/error.hpp>
#include <aedis/detail/net.hpp>
#include <aedis/resp3/type.hpp>
@@ -22,10 +23,8 @@
#include <aedis/resp3/read.hpp>
#include <aedis/resp3/exec.hpp>
#include <aedis/resp3/write.hpp>
#include <aedis/generic/adapt.hpp>
namespace aedis {
namespace generic {
namespace detail {
#include <boost/asio/yield.hpp>
@@ -252,7 +251,7 @@ struct ping_op {
cli->req_.clear();
cli->req_.push(Command::ping);
yield cli->async_exec(cli->req_, generic::adapt(), std::move(self));
yield cli->async_exec(cli->req_, aedis::adapt(), std::move(self));
if (ec) {
self.complete(ec);
return;
@@ -516,7 +515,6 @@ struct reader_op {
#include <boost/asio/unyield.hpp>
} // detail
} // generic
} // aedis
#endif // AEDIS_GENERIC_CONNECTION_OPS_HPP
#endif // AEDIS_CONNECTION_OPS_HPP

View File

@@ -4,10 +4,9 @@
* accompanying file LICENSE.txt)
*/
#include <aedis/redis/command.hpp>
#include <aedis/command.hpp>
namespace aedis {
namespace redis {
char const* to_string(command c)
{
@@ -143,6 +142,7 @@ char const* to_string(command c)
"SDIFF",
"SDIFFSTORE",
"SELECT",
"SENTINEL",
"SET",
"SETBIT",
"SETEX",
@@ -241,5 +241,4 @@ bool has_push_response(command cmd)
}
}
} // redis
} // aedis

View File

@@ -1,78 +0,0 @@
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
*
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE.txt)
*/
#ifndef AEDIS_SENTINEL_COMMAND_HPP
#define AEDIS_SENTINEL_COMMAND_HPP
#include <ostream>
namespace aedis {
namespace sentinel {
/** \brief Sentinel commands.
* \ingroup any
*
* The full list of Sentinel commands can be found at
* https://redis.io/topics/sentinel.
*
* \remark This list was created with the help of the \c command
* command.
*/
enum class command {
/// https://redis.io/commands/acl
acl,
/// https://redis.io/commands/auth
auth,
/// https://redis.io/commands/client
client,
/// https://redis.io/commands/command
command,
/// https://redis.io/commands/hello
hello,
/// https://redis.io/commands/info
info,
/// https://redis.io/commands/ping
ping,
/// https://redis.io/commands/psubscribe
psubscribe,
/// https://redis.io/commands/publish
publish,
/// https://redis.io/commands/punsubscribe
punsubscribe,
/// https://redis.io/commands/role
role,
/// https://redis.io/topics/sentinel
sentinel,
/// https://redis.io/commands/shutdown
shutdown,
/// https://redis.io/commands/subscribe
subscribe,
/// https://redis.io/commands/unsubscribe
unsubscribe,
/// Unknown/invalid command.
invalid,
};
/** \brief Converts the command to a string.
* \ingroup any
* \param c The command to convert.
*/
char const* to_string(command c);
/** \brief Writes the command string to the stream.
* \ingroup any
* \param os Output stream.
* \param c Sentinel command
*/
std::ostream& operator<<(std::ostream& os, command c);
// Checks whether a command has push response.
bool has_push_response(command cmd);
} // sentinel
} // aedis
#endif // AEDIS_SENTINEL_COMMAND_HPP

View File

@@ -1,55 +0,0 @@
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
*
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE.txt)
*/
#include <aedis/sentinel/command.hpp>
namespace aedis {
namespace sentinel {
char const* to_string(command c)
{
static char const* table[] = {
"ACL",
"AUTH",
"CLIENT",
"COMMAND",
"HELLO",
"INFO",
"PING",
"PSUBSCRIBE",
"PUBLISH",
"PUNSUBSCRIBE",
"ROLE",
"SENTINEL",
"SHUTDOWN",
"SUBSCRIBE",
"UNSUBSCRIBE",
};
return table[static_cast<int>(c)];
}
std::ostream& operator<<(std::ostream& os, command c)
{
os << to_string(c);
return os;
}
bool has_push_response(command cmd)
{
switch (cmd) {
case command::subscribe:
case command::unsubscribe:
case command::psubscribe:
return true;
default:
return false;
}
}
} // sentinel
} // aedis

View File

@@ -5,9 +5,8 @@
*/
#include <aedis/impl/error.ipp>
#include <aedis/impl/command.ipp>
#include <aedis/resp3/impl/type.ipp>
#include <aedis/resp3/detail/impl/parser.ipp>
#include <aedis/resp3/impl/error.ipp>
#include <aedis/redis/impl/command.ipp>
#include <aedis/adapter/impl/error.ipp>
#include <aedis/sentinel/impl/command.ipp>

View File

@@ -15,9 +15,9 @@
namespace net = boost::asio;
namespace adapter = aedis::adapter;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using connection = aedis::generic::connection<command>;
using connection = aedis::connection<command>;
using node_type = aedis::resp3::node<boost::string_view>;
using error_code = boost::system::error_code;

View File

@@ -14,12 +14,12 @@
#include <aedis/src.hpp>
namespace net = boost::asio;
namespace generic = aedis::generic;
using aedis::adapt;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using tcp_socket = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::socket>;
using tcp_acceptor = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::acceptor>;
using connection = aedis::generic::connection<command, tcp_socket>;
using connection = aedis::connection<command, tcp_socket>;
using response_type = std::vector<aedis::resp3::node<std::string>>;
class user_session:
@@ -106,7 +106,7 @@ reader(
co_await db->async_exec(req);
for (response_type resp;;) {
co_await db->async_read_push(generic::adapt(resp));
co_await db->async_read_push(adapt(resp));
for (auto& session: *sessions)
session->deliver(resp.at(3).value);

View File

@@ -15,11 +15,11 @@
#include "mystruct.hpp"
namespace net = boost::asio;
namespace generic = aedis::generic;
using boost::optional;
using aedis::adapt;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using connection = aedis::generic::connection<command>;
using connection = aedis::connection<command>;
// Response used in this example.
using C1 = std::vector<int>;
@@ -62,8 +62,8 @@ int main()
std::string // quit
> resp;
db.async_exec(req1, generic::adapt(), handler);
db.async_exec(req2, generic::adapt(resp), handler);
db.async_exec(req1, aedis::adapt(), handler);
db.async_exec(req2, aedis::adapt(resp), handler);
db.async_run("127.0.0.1", "6379", handler);
ioc.run();

View File

@@ -11,12 +11,12 @@
#include <aedis/src.hpp>
namespace net = boost::asio;
namespace generic = aedis::generic;
using aedis::adapt;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using tcp_socket = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::socket>;
using tcp_acceptor = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::acceptor>;
using connection = generic::connection<command, tcp_socket>;
using connection = aedis::connection<command, tcp_socket>;
net::awaitable<void> echo_loop(tcp_socket socket, std::shared_ptr<connection> db)
{
@@ -26,7 +26,7 @@ net::awaitable<void> echo_loop(tcp_socket socket, std::shared_ptr<connection> db
request<command> req;
req.push(command::ping, buffer);
std::tuple<std::string> resp;
co_await db->async_exec(req, generic::adapt(resp));
co_await db->async_exec(req, adapt(resp));
co_await net::async_write(socket, net::buffer(std::get<0>(resp)));
buffer.erase(0, n);
}

View File

@@ -11,11 +11,11 @@
#include <aedis/src.hpp>
namespace net = boost::asio;
namespace generic = aedis::generic;
using aedis::adapt;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using connection = generic::connection<command>;
using connection = aedis::connection<command>;
auto handler =[](auto ec, auto...)
{ std::cout << ec.message() << std::endl; };
@@ -30,7 +30,7 @@ int main()
net::io_context ioc;
connection db{ioc};
db.async_exec(req, generic::adapt(resp), handler);
db.async_exec(req, adapt(resp), handler);
db.async_run("127.0.0.1", "6379", handler);
ioc.run();

View File

@@ -19,7 +19,6 @@ namespace net = boost::asio;
using aedis::resp3::node;
using aedis::adapter::adapt;
using aedis::adapter::adapter_t;
using aedis::redis::command;
void print_aggr(std::vector<aedis::resp3::node<std::string>>& v)
{

View File

@@ -13,11 +13,11 @@
#include <aedis/src.hpp>
namespace net = boost::asio;
namespace generic = aedis::generic;
using aedis::adapt;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using tcp_socket = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::socket>;
using connection = generic::connection<command, tcp_socket>;
using connection = aedis::connection<command, tcp_socket>;
using response_type = std::vector<aedis::resp3::node<std::string>>;
/* In this example we send a subscription to a channel and start
@@ -41,7 +41,7 @@ net::awaitable<void> reader(std::shared_ptr<connection> db)
co_await db->async_exec(req);
for (response_type resp;;) {
auto n = co_await db->async_read_push(generic::adapt(resp));
auto n = co_await db->async_read_push(adapt(resp));
std::cout
<< "Size: " << n << "\n"
<< "Event: " << resp.at(1).value << "\n"

View File

@@ -20,11 +20,10 @@
namespace net = boost::asio;
namespace resp3 = aedis::resp3;
namespace generic = aedis::generic;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using connection = aedis::generic::connection<command>;
using connection = aedis::connection<command>;
using error_code = boost::system::error_code;
using net::experimental::as_tuple;
using tcp = net::ip::tcp;
@@ -75,7 +74,7 @@ void test_quit()
request<command> req;
req.push(command::quit);
db->async_exec(req, generic::adapt(), [](auto ec, auto r){
db->async_exec(req, aedis::adapt(), [](auto ec, auto r){
expect_no_error(ec);
//expect_eq(w, 36UL);
//expect_eq(r, 152UL);
@@ -94,12 +93,12 @@ net::awaitable<void>
push_consumer3(std::shared_ptr<connection> db)
{
{
auto [ec, n] = co_await db->async_read_push(generic::adapt(), as_tuple(net::use_awaitable));
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_no_error(ec);
}
{
auto [ec, n] = co_await db->async_read_push(generic::adapt(), as_tuple(net::use_awaitable));
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_error(ec, boost::asio::error::operation_aborted);
}
}
@@ -113,7 +112,7 @@ void test_push()
req.push(command::subscribe, "channel");
req.push(command::quit);
db->async_exec(req, generic::adapt(), [](auto ec, auto r){
db->async_exec(req, aedis::adapt(), [](auto ec, auto r){
expect_no_error(ec);
//expect_eq(w, 68UL);
//expect_eq(r, 151UL);
@@ -135,7 +134,7 @@ net::awaitable<void> run5(std::shared_ptr<connection> db)
{
request<command> req;
req.push(command::quit);
db->async_exec(req, generic::adapt(), [](auto ec, auto){
db->async_exec(req, aedis::adapt(), [](auto ec, auto){
expect_no_error(ec);
});
@@ -146,7 +145,7 @@ net::awaitable<void> run5(std::shared_ptr<connection> db)
{
request<command> req;
req.push(command::quit);
db->async_exec(req, generic::adapt(), [](auto ec, auto){
db->async_exec(req, aedis::adapt(), [](auto ec, auto){
expect_no_error(ec);
});
@@ -180,7 +179,7 @@ void test_idle()
request<command> req;
req.push(command::client, "PAUSE", 5000);
db->async_exec(req, generic::adapt(), [](auto ec, auto r){
db->async_exec(req, aedis::adapt(), [](auto ec, auto r){
expect_no_error(ec);
});

View File

@@ -15,8 +15,8 @@
namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using aedis::adapter::adapt;
using net::ip::tcp;

View File

@@ -16,8 +16,8 @@
namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::command;
using aedis::resp3::request;
using aedis::redis::command;
using aedis::resp3::node;
using aedis::adapter::adapt;
using net::ip::tcp;