diff --git a/Makefile.am b/Makefile.am index 2cb4edf3..eedd80b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/aedis/generic/adapt.hpp b/aedis/adapt.hpp similarity index 95% rename from aedis/generic/adapt.hpp rename to aedis/adapt.hpp index bc72c3cd..8bf28eb9 100644 --- a/aedis/generic/adapt.hpp +++ b/aedis/adapt.hpp @@ -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 @@ -19,7 +19,6 @@ #include namespace aedis { -namespace generic { namespace detail { struct ignore_adapter { @@ -128,7 +127,6 @@ auto adapt(T& t) noexcept return detail::response_traits::adapt(t); } -} // generic } // aedis -#endif // AEDIS_GENERIC_ADAPT_HPP +#endif // AEDIS_ADAPT_HPP diff --git a/aedis/aedis.hpp b/aedis/aedis.hpp index 27e2bd44..ef0c6699 100644 --- a/aedis/aedis.hpp +++ b/aedis/aedis.hpp @@ -8,16 +8,15 @@ #define AEDIS_HPP #include +#include +#include +#include #include #include #include #include #include #include -#include -#include -#include -#include /** \mainpage Documentation \tableofcontents diff --git a/aedis/redis/command.hpp b/aedis/command.hpp similarity index 98% rename from aedis/redis/command.hpp rename to aedis/command.hpp index 3f882595..7e71b32c 100644 --- a/aedis/redis/command.hpp +++ b/aedis/command.hpp @@ -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 #include 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 diff --git a/aedis/generic/connection.hpp b/aedis/connection.hpp similarity index 97% rename from aedis/generic/connection.hpp rename to aedis/connection.hpp index 331a2105..5fd701c0 100644 --- a/aedis/generic/connection.hpp +++ b/aedis/connection.hpp @@ -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 #include @@ -17,12 +17,11 @@ #include #include +#include #include -#include -#include +#include 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 diff --git a/aedis/generic/detail/connection_ops.hpp b/aedis/detail/connection_ops.hpp similarity index 98% rename from aedis/generic/detail/connection_ops.hpp rename to aedis/detail/connection_ops.hpp index 87b70b12..99deb125 100644 --- a/aedis/generic/detail/connection_ops.hpp +++ b/aedis/detail/connection_ops.hpp @@ -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 @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -22,10 +23,8 @@ #include #include #include -#include namespace aedis { -namespace generic { namespace detail { #include @@ -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 } // detail -} // generic } // aedis -#endif // AEDIS_GENERIC_CONNECTION_OPS_HPP +#endif // AEDIS_CONNECTION_OPS_HPP diff --git a/aedis/redis/impl/command.ipp b/aedis/impl/command.ipp similarity index 98% rename from aedis/redis/impl/command.ipp rename to aedis/impl/command.ipp index 84c004c0..e2c601de 100644 --- a/aedis/redis/impl/command.ipp +++ b/aedis/impl/command.ipp @@ -4,10 +4,9 @@ * accompanying file LICENSE.txt) */ -#include +#include 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 diff --git a/aedis/sentinel/command.hpp b/aedis/sentinel/command.hpp deleted file mode 100644 index 0ae40f4a..00000000 --- a/aedis/sentinel/command.hpp +++ /dev/null @@ -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 - -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 diff --git a/aedis/sentinel/impl/command.ipp b/aedis/sentinel/impl/command.ipp deleted file mode 100644 index 177b25f5..00000000 --- a/aedis/sentinel/impl/command.ipp +++ /dev/null @@ -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 - -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(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 diff --git a/aedis/src.hpp b/aedis/src.hpp index 6da73e03..03d64d73 100644 --- a/aedis/src.hpp +++ b/aedis/src.hpp @@ -5,9 +5,8 @@ */ #include +#include #include #include #include -#include #include -#include diff --git a/examples/adapter.cpp b/examples/adapter.cpp index 53ac594d..a18f6015 100644 --- a/examples/adapter.cpp +++ b/examples/adapter.cpp @@ -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; +using connection = aedis::connection; using node_type = aedis::resp3::node; using error_code = boost::system::error_code; diff --git a/examples/chat_room.cpp b/examples/chat_room.cpp index 03f6004f..f0132637 100644 --- a/examples/chat_room.cpp +++ b/examples/chat_room.cpp @@ -14,12 +14,12 @@ #include 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; using tcp_acceptor = net::use_awaitable_t<>::as_default_on_t; -using connection = aedis::generic::connection; +using connection = aedis::connection; using response_type = std::vector>; 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); diff --git a/examples/containers.cpp b/examples/containers.cpp index 7b4a3e2b..753e9f6e 100644 --- a/examples/containers.cpp +++ b/examples/containers.cpp @@ -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; +using connection = aedis::connection; // Response used in this example. using C1 = std::vector; @@ -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(); diff --git a/examples/echo_server.cpp b/examples/echo_server.cpp index da0e1b6a..a3fa2f4c 100644 --- a/examples/echo_server.cpp +++ b/examples/echo_server.cpp @@ -11,12 +11,12 @@ #include 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; using tcp_acceptor = net::use_awaitable_t<>::as_default_on_t; -using connection = generic::connection; +using connection = aedis::connection; net::awaitable echo_loop(tcp_socket socket, std::shared_ptr db) { @@ -26,7 +26,7 @@ net::awaitable echo_loop(tcp_socket socket, std::shared_ptr db request req; req.push(command::ping, buffer); std::tuple 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); } diff --git a/examples/intro.cpp b/examples/intro.cpp index dc7919f5..a68b685e 100644 --- a/examples/intro.cpp +++ b/examples/intro.cpp @@ -11,11 +11,11 @@ #include 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; +using connection = aedis::connection; 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(); diff --git a/examples/print.hpp b/examples/print.hpp index 2fe90c88..806da7aa 100644 --- a/examples/print.hpp +++ b/examples/print.hpp @@ -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>& v) { diff --git a/examples/subscriber.cpp b/examples/subscriber.cpp index 06720793..b2a21e28 100644 --- a/examples/subscriber.cpp +++ b/examples/subscriber.cpp @@ -13,11 +13,11 @@ #include 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; -using connection = generic::connection; +using connection = aedis::connection; using response_type = std::vector>; /* In this example we send a subscription to a channel and start @@ -41,7 +41,7 @@ net::awaitable reader(std::shared_ptr 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" diff --git a/tests/high_level.cpp b/tests/high_level.cpp index 70f556d3..86d74f37 100644 --- a/tests/high_level.cpp +++ b/tests/high_level.cpp @@ -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; +using connection = aedis::connection; 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 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 push_consumer3(std::shared_ptr 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 run5(std::shared_ptr db) { request 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 run5(std::shared_ptr db) { request 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 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); }); diff --git a/tests/intro_sync.cpp b/tests/intro_sync.cpp index 8da6b73e..002e225e 100644 --- a/tests/intro_sync.cpp +++ b/tests/intro_sync.cpp @@ -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; diff --git a/tools/commands.cpp b/tools/commands.cpp index 19345677..ad4ba55f 100644 --- a/tools/commands.cpp +++ b/tools/commands.cpp @@ -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;