From 6e79ecc9f45b0316965dbfbd1c7065381a988bd0 Mon Sep 17 00:00:00 2001 From: Marcelo Zimbres Date: Sun, 15 Aug 2021 09:07:39 +0200 Subject: [PATCH] Refactoring: - Progresses with caching. - Renaming and simplifications. - Renames enum commands to command. - Renames enum types to type. --- Makefile.am | 4 +- examples/async_basic.cpp | 13 +- include/aedis/aedis.hpp | 2 +- include/aedis/{commands.hpp => command.hpp} | 6 +- include/aedis/connection.hpp | 36 ++- include/aedis/detail/impl/read.ipp | 8 +- .../aedis/detail/impl/response_buffers.ipp | 80 +++---- include/aedis/detail/read.hpp | 63 +++--- include/aedis/detail/response_base.hpp | 2 +- include/aedis/detail/response_buffers.hpp | 12 +- include/aedis/detail/responses.hpp | 46 ++-- include/aedis/detail/write.hpp | 22 +- include/aedis/impl/commands.ipp | 8 +- include/aedis/impl/connection.ipp | 1 + include/aedis/impl/src.hpp | 2 +- include/aedis/impl/{types.ipp => type.ipp} | 51 +++-- include/aedis/{request.hpp => pipeline.hpp} | 214 +++++++++--------- include/aedis/receiver_base.hpp | 11 +- include/aedis/{resp_types.hpp => type.hpp} | 38 +++- include/aedis/types.hpp | 39 ---- tests/general.cpp | 23 +- 21 files changed, 340 insertions(+), 341 deletions(-) rename include/aedis/{commands.hpp => command.hpp} (89%) rename include/aedis/impl/{types.ipp => type.ipp} (50%) rename include/aedis/{request.hpp => pipeline.hpp} (68%) rename include/aedis/{resp_types.hpp => type.hpp} (68%) delete mode 100644 include/aedis/types.hpp diff --git a/Makefile.am b/Makefile.am index b9ec2562..a7f744f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,20 +20,20 @@ libaedis_a_SOURCES += $(top_srcdir)/aedis/receiver_base.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/request.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/resp_types.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/type.hpp +libaedis_a_SOURCES += $(top_srcdir)/aedis/command.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/version.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/write.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/impl/connection.ipp libaedis_a_SOURCES += $(top_srcdir)/aedis/impl/read.ipp libaedis_a_SOURCES += $(top_srcdir)/aedis/impl/src.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/impl/type.ipp -libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/command.hpp +libaedis_a_SOURCES += $(top_srcdir)/aedis/impl/command.ipp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/parser.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/response_base.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/response_buffers.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/response_types.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/responses.hpp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/utils.hpp -libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/impl/command.ipp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/impl/parser.ipp libaedis_a_SOURCES += $(top_srcdir)/aedis/detail/impl/response_buffers.ipp libaedis_a_SOURCES += $(top_srcdir)/src/aedis.cpp diff --git a/examples/async_basic.cpp b/examples/async_basic.cpp index f0fc917a..4a426c73 100644 --- a/examples/async_basic.cpp +++ b/examples/async_basic.cpp @@ -10,13 +10,6 @@ using namespace aedis; -void f(request& req) -{ - req.ping(); - req.psubscribe({"aaa*"}); - req.quit(); -} - class myreceiver : public receiver_base { private: std::shared_ptr conn_; @@ -25,7 +18,11 @@ public: myreceiver(std::shared_ptr conn) : conn_{conn} { } void on_hello(array_type& v) noexcept override - { conn_->send(f); } + { + conn_->ping(); + conn_->psubscribe({"aaa*"}); + conn_->quit(); + } void on_ping(simple_string_type& s) noexcept override { std::cout << "PING: " << s << std::endl; } diff --git a/include/aedis/aedis.hpp b/include/aedis/aedis.hpp index a1054edc..907cf9e7 100644 --- a/include/aedis/aedis.hpp +++ b/include/aedis/aedis.hpp @@ -7,7 +7,7 @@ #pragma once -#include +#include #include #include #include diff --git a/include/aedis/commands.hpp b/include/aedis/command.hpp similarity index 89% rename from include/aedis/commands.hpp rename to include/aedis/command.hpp index 269fdd45..cd2dad49 100644 --- a/include/aedis/commands.hpp +++ b/include/aedis/command.hpp @@ -11,7 +11,7 @@ namespace aedis { -enum class commands +enum class command { acl_load , acl_save , acl_list @@ -73,8 +73,8 @@ enum class commands , unknown }; -std::string to_string(commands c); -std::ostream& operator<<(std::ostream& os, commands c); +std::string to_string(command c); +std::ostream& operator<<(std::ostream& os, command c); } // aedis diff --git a/include/aedis/connection.hpp b/include/aedis/connection.hpp index dea192f8..64bbdb39 100644 --- a/include/aedis/connection.hpp +++ b/include/aedis/connection.hpp @@ -14,8 +14,8 @@ #include #include "net.hpp" -#include "types.hpp" -#include "request.hpp" +#include "type.hpp" +#include "pipeline.hpp" namespace aedis { @@ -47,7 +47,7 @@ private: net::ip::tcp::socket socket_; std::string buffer_; detail::response_buffers resps_; - detail::request_queue reqs_; + std::queue reqs_; bool reconnect_ = false; config conf_; boost::system::error_code ec_; @@ -74,12 +74,12 @@ public: if (empty || std::size(reqs_) == 1) reqs_.push({}); - auto const pipeline_size = std::ssize(reqs_.back().req); - auto const payload_size = std::ssize(reqs_.back().req.payload); + auto const pipeline_size = std::ssize(reqs_.back()); + auto const payload_size = std::ssize(reqs_.back().payload); if (pipeline_size > conf_.max_pipeline_size || payload_size > conf_.max_payload_size) reqs_.push({}); - filler(reqs_.back().req); + filler(reqs_.back()); if (empty) { co_spawn( @@ -95,6 +95,30 @@ public: { return std::ssize(reqs_); } void enable_reconnect() noexcept; + + /// Adds ping to the request, see https://redis.io/commands/bgrewriteaof + void ping() + { send([](auto& req){ req.ping();}); } + + /// Adds ping to the request, see https://redis.io/commands/psubscribe + void psubscribe(std::initializer_list l) + { send([&](auto& req){ req.psubscribe(l);}); } + + /// Adds quit to the request, see https://redis.io/commands/quit + void quit() + { send([](auto& req){ req.quit();}); } + + /// Adds multi to the request, see https://redis.io/commands/multi + void multi() + { send([](auto& req){ req.multi();}); } + + /// Adds multi to the request, see https://redis.io/commands/exec + void exec() + { send([](auto& req){ req.exec();}); } + + /// Adds incr to the request, see https://redis.io/commands/incr + void incr(std::string_view key) + { send([&](auto& req){ req.incr(key);}); } }; } // aedis diff --git a/include/aedis/detail/impl/read.ipp b/include/aedis/detail/impl/read.ipp index f14b1c35..e8e789a6 100644 --- a/include/aedis/detail/impl/read.ipp +++ b/include/aedis/detail/impl/read.ipp @@ -9,13 +9,13 @@ namespace aedis { namespace detail { -bool queue_pop(request_queue& reqs) +bool queue_pop(std::queue& reqs) { assert(!std::empty(reqs)); - assert(!std::empty(reqs.front().req.cmds)); + assert(!std::empty(reqs.front().cmds)); - reqs.front().req.cmds.pop(); - if (std::empty(reqs.front().req.cmds)) { + reqs.front().cmds.pop(); + if (std::empty(reqs.front().cmds)) { reqs.pop(); return true; } diff --git a/include/aedis/detail/impl/response_buffers.ipp b/include/aedis/detail/impl/response_buffers.ipp index c5056a59..d7cd3ca1 100644 --- a/include/aedis/detail/impl/response_buffers.ipp +++ b/include/aedis/detail/impl/response_buffers.ipp @@ -12,27 +12,27 @@ namespace aedis { namespace detail { void response_buffers::forward_transaction( - std::deque> const& ids, + std::deque> const& ids, receiver_base& recv) { assert(std::size(ids) == std::size(tree_.result)); for (auto i = 0U; i < std::size(ids); ++i) - tree_.result[i].command = ids[i].first; + tree_.result[i].cmd = ids[i].first; recv.on_transaction(tree_.result); } -void response_buffers::forward(commands cmd, types t, receiver_base& recv) +void response_buffers::forward(command cmd, resp3::type type, receiver_base& recv) { - switch (t) { - case types::push: + switch (type) { + case resp3::type::push: { - assert(t == types::push); + assert(type == resp3::type::push); recv.on_push(push_.result); push_.result.clear(); } break; - case types::set: + case resp3::type::set: { switch (cmd) { EXPAND_RECEIVER_CASE(set_, smembers); @@ -40,7 +40,7 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } set_.result.clear(); } break; - case types::map: + case resp3::type::map: { switch (cmd) { EXPAND_RECEIVER_CASE(map_, hello); @@ -49,7 +49,7 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } map_.result.clear(); } break; - case types::array: + case resp3::type::array: { switch (cmd) { EXPAND_RECEIVER_CASE(array_, acl_list); @@ -67,7 +67,7 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } array_.result.clear(); } break; - case types::simple_string: + case resp3::type::simple_string: { switch (cmd) { EXPAND_RECEIVER_CASE(simple_string_, acl_load); @@ -83,7 +83,7 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } simple_string_.result.clear(); } break; - case types::number: + case resp3::type::number: { switch (cmd) { EXPAND_RECEIVER_CASE(number_, acl_deluser); @@ -103,27 +103,27 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) default: {assert(false);} } } break; - case types::double_type: + case resp3::type::double_type: { switch (cmd) { default: {assert(false);} } } break; - case types::big_number: + case resp3::type::big_number: { switch (cmd) { default: {assert(false);} } big_number_.result.clear(); } break; - case types::boolean: + case resp3::type::boolean: { switch (cmd) { default: {assert(false);} } bool_.result = false; } break; - case types::blob_string: + case resp3::type::blob_string: { switch (cmd) { EXPAND_RECEIVER_CASE(blob_string_, acl_genpass); @@ -135,35 +135,35 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } blob_string_.result.clear(); } break; - case types::verbatim_string: + case resp3::type::verbatim_string: { switch (cmd) { default: {assert(false);} } verbatim_string_.result.clear(); } break; - case types::streamed_string_part: + case resp3::type::streamed_string_part: { switch (cmd) { default: {assert(false);} } streamed_string_part_.result.clear(); } break; - case types::simple_error: + case resp3::type::simple_error: { recv.on_simple_error(cmd, simple_error_.result); simple_error_.result.clear(); } break; - case types::blob_error: + case resp3::type::blob_error: { recv.on_blob_error(cmd, blob_error_.result); blob_error_.result.clear(); } break; - case types::null: + case resp3::type::null: { recv.on_null(cmd); } break; - case types::attribute: + case resp3::type::attribute: { throw std::runtime_error("Attribute are not supported yet."); } break; @@ -171,28 +171,28 @@ void response_buffers::forward(commands cmd, types t, receiver_base& recv) } } -response_base* response_buffers::select(commands cmd, types t) +response_base* response_buffers::select(command cmd, resp3::type type) { - if (cmd == commands::exec) + if (cmd == command::exec) return &tree_; - switch (t) { - case types::push: return &push_; - case types::set: return &set_; - case types::map: return &map_; - case types::attribute: return &attribute_; - case types::array: return &array_; - case types::simple_error: return &simple_error_; - case types::simple_string: return &simple_string_; - case types::number: return &number_; - case types::double_type: return &double_; - case types::big_number: return &big_number_; - case types::boolean: return &bool_; - case types::blob_error: return &blob_error_; - case types::blob_string: return &blob_string_; - case types::verbatim_string: return &verbatim_string_; - case types::streamed_string_part: return &streamed_string_part_; - case types::null: return &ignore_; + switch (type) { + case resp3::type::push: return &push_; + case resp3::type::set: return &set_; + case resp3::type::map: return &map_; + case resp3::type::attribute: return &attribute_; + case resp3::type::array: return &array_; + case resp3::type::simple_error: return &simple_error_; + case resp3::type::simple_string: return &simple_string_; + case resp3::type::number: return &number_; + case resp3::type::double_type: return &double_; + case resp3::type::big_number: return &big_number_; + case resp3::type::boolean: return &bool_; + case resp3::type::blob_error: return &blob_error_; + case resp3::type::blob_string: return &blob_string_; + case resp3::type::verbatim_string: return &verbatim_string_; + case resp3::type::streamed_string_part: return &streamed_string_part_; + case resp3::type::null: return &ignore_; default: { throw std::runtime_error("response_buffers"); return nullptr; diff --git a/include/aedis/detail/read.hpp b/include/aedis/detail/read.hpp index 4bd7b572..a553a342 100644 --- a/include/aedis/detail/read.hpp +++ b/include/aedis/detail/read.hpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include "parser.hpp" #include "response_buffers.hpp" @@ -180,10 +180,10 @@ class type_op { private: AsyncReadStream& stream_; Storage* buf_ = nullptr; - types* t_; + resp3::type* t_; public: - type_op(AsyncReadStream& stream, Storage* buf, types* t) + type_op(AsyncReadStream& stream, Storage* buf, resp3::type* t) : stream_ {stream} , buf_ {buf} , t_ {t} @@ -209,7 +209,7 @@ public: } assert(!std::empty(*buf_)); - *t_ = to_type(buf_->front()); + *t_ = resp3::to_type(buf_->front()); return self.complete(ec); } }; @@ -223,7 +223,7 @@ template < auto async_read_type( AsyncReadStream& stream, Storage& buffer, - types& t, + resp3::type& t, CompletionToken&& token = net::default_completion_token_t{}) { @@ -235,17 +235,10 @@ auto async_read_type( stream); } -struct queue_elem { - request req; - bool sent = false; -}; +// Returns true when a new pipeline can be sent to redis. +bool queue_pop(std::queue& reqs); -using request_queue = std::queue; - -// Returns true when a new request can be sent to redis. -bool queue_pop(request_queue& reqs); - -using transaction_queue_type = std::deque>; +using transaction_queue_type = std::deque>; // TODO: Implement as a composed operation. template @@ -254,13 +247,13 @@ async_read_transaction( AsyncReadWriteStream& socket, Storage& buffer, response_base& reader, - request_queue& reqs, + std::queue& reqs, boost::system::error_code& ec) { transaction_queue_type trans; for (;;) { - auto const cmd = reqs.front().req.cmds.front(); - if (cmd != commands::exec) { + auto const cmd = reqs.front().cmds.front(); + if (cmd != command::exec) { response_static_string<6> tmp; co_await async_read(socket, buffer, tmp, net::redirect_error(net::use_awaitable, ec)); @@ -268,21 +261,21 @@ async_read_transaction( co_return transaction_queue_type{}; // Failing to QUEUE a command inside a trasaction is - // considered an application error. The multi commands + // considered an application error. The multi command // always gets a "OK" response and all other commands get // QUEUED unless the user is e.g. using wrong data types. - auto const* res = cmd == commands::multi ? "OK" : "QUEUED"; + auto const* res = cmd == command::multi ? "OK" : "QUEUED"; assert (tmp.result == res); // Pushes the command in the transction command queue that will be // processed when exec arrives. - trans.push_back({reqs.front().req.cmds.front(), types::invalid}); - reqs.front().req.cmds.pop(); + trans.push_back({reqs.front().cmds.front(), resp3::type::invalid}); + reqs.front().cmds.pop(); continue; } - if (cmd == commands::exec) { - assert(trans.front().first == commands::multi); + if (cmd == command::exec) { + assert(trans.front().first == command::multi); co_await async_read(socket, buffer, reader, net::redirect_error(net::use_awaitable, ec)); if (ec) co_return transaction_queue_type{}; @@ -307,38 +300,38 @@ async_reader( Storage& buffer, ResponseBuffers& resps, Receiver& recv, - request_queue& reqs, + std::queue& reqs, boost::system::error_code& ec) { for (;;) { - auto t = types::invalid; + auto t = resp3::type::invalid; co_await async_read_type(socket, buffer, t, net::redirect_error(net::use_awaitable, ec)); if (ec) co_return; - assert(t != types::invalid); + assert(t != resp3::type::invalid); - if (t == types::push) { - auto* tmp = resps.select(commands::unknown, types::push); + if (t == resp3::type::push) { + auto* tmp = resps.select(command::unknown, resp3::type::push); co_await async_read(socket, buffer, *tmp, net::redirect_error(net::use_awaitable, ec)); if (ec) co_return; - resps.forward(commands::unknown, types::push, recv); + resps.forward(command::unknown, resp3::type::push, recv); continue; } assert(!std::empty(reqs)); - assert(!std::empty(reqs.front().req.cmds)); + assert(!std::empty(reqs.front().cmds)); - if (reqs.front().req.cmds.front() == commands::multi) { + if (reqs.front().cmds.front() == command::multi) { // The exec response is an array where each element is the // response of one command in the transaction. This requires // a special response buffer, that can deal with recursive // data types. - auto* reader = resps.select(commands::exec, types::invalid); + auto* reader = resps.select(command::exec, resp3::type::invalid); auto const trans_queue = co_await async_read_transaction( @@ -359,7 +352,7 @@ async_reader( continue; } - auto const cmd = reqs.front().req.cmds.front(); + auto const cmd = reqs.front().cmds.front(); auto* tmp = resps.select(cmd, t); co_await async_read(socket, buffer, *tmp, net::redirect_error(net::use_awaitable, ec)); diff --git a/include/aedis/detail/response_base.hpp b/include/aedis/detail/response_base.hpp index 2b40ba0b..e62f9ef3 100644 --- a/include/aedis/detail/response_base.hpp +++ b/include/aedis/detail/response_base.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include namespace aedis { namespace detail { diff --git a/include/aedis/detail/response_buffers.hpp b/include/aedis/detail/response_buffers.hpp index 072713da..22be6aca 100644 --- a/include/aedis/detail/response_buffers.hpp +++ b/include/aedis/detail/response_buffers.hpp @@ -7,15 +7,15 @@ #pragma once -#include +#include #include -#include +#include #include "responses.hpp" namespace aedis { namespace detail { -#define EXPAND_RECEIVER_CASE(var, x) case commands::x: recv.on_##x(var.result); break +#define EXPAND_RECEIVER_CASE(var, x) case command::x: recv.on_##x(var.result); break class response_buffers { private: @@ -41,13 +41,13 @@ private: public: // When the cmd is from a transaction the type of the message is // not specified. - response_base* select(commands cmd, types t); + response_base* select(command cmd, resp3::type t); void forward_transaction( - std::deque> const& ids, + std::deque> const& ids, receiver_base& recv); - void forward(commands cmd, types t, receiver_base& recv); + void forward(command cmd, resp3::type type, receiver_base& recv); }; } // detail diff --git a/include/aedis/detail/responses.hpp b/include/aedis/detail/responses.hpp index 9d1d9944..afcd9918 100644 --- a/include/aedis/detail/responses.hpp +++ b/include/aedis/detail/responses.hpp @@ -18,11 +18,9 @@ #include #include -#include -#include -#include +#include +#include #include -#include #include "response_base.hpp" @@ -71,7 +69,7 @@ public: private: int depth_ = 0; - void add_aggregate(int n, types type) + void add_aggregate(int n, resp3::type type) { if (depth_ == 0) { result.reserve(n); @@ -84,35 +82,35 @@ private: ++depth_; } - void add(std::string_view s, types t) + void add(std::string_view s, resp3::type type) { if (std::empty(result)) { - result.emplace_back(depth_, t, 1, commands::unknown, std::vector{std::string{s}}); + result.emplace_back(depth_, type, 1, command::unknown, std::vector{std::string{s}}); } else if (std::ssize(result.back().value) == result.back().expected_size) { - result.emplace_back(depth_, t, 1, commands::unknown, std::vector{std::string{s}}); + result.emplace_back(depth_, type, 1, command::unknown, std::vector{std::string{s}}); } else { result.back().value.push_back(std::string{s}); } } public: - void select_array(int n) override {add_aggregate(n, types::array);} - void select_push(int n) override {add_aggregate(n, types::push);} - void select_set(int n) override {add_aggregate(n, types::set);} - void select_map(int n) override {add_aggregate(n, types::map);} - void select_attribute(int n) override {add_aggregate(n, types::attribute);} + void select_array(int n) override {add_aggregate(n, resp3::type::array);} + void select_push(int n) override {add_aggregate(n, resp3::type::push);} + void select_set(int n) override {add_aggregate(n, resp3::type::set);} + void select_map(int n) override {add_aggregate(n, resp3::type::map);} + void select_attribute(int n) override {add_aggregate(n, resp3::type::attribute);} - void on_simple_string(std::string_view s) override { add(s, types::simple_string); } - void on_simple_error(std::string_view s) override { add(s, types::simple_error); } - void on_number(std::string_view s) override {add(s, types::number);} - void on_double(std::string_view s) override {add(s, types::double_type);} - void on_bool(std::string_view s) override {add(s, types::boolean);} - void on_big_number(std::string_view s) override {add(s, types::big_number);} - void on_null() override {add({}, types::null);} - void on_blob_error(std::string_view s = {}) override {add(s, types::blob_error);} - void on_verbatim_string(std::string_view s = {}) override {add(s, types::verbatim_string);} - void on_blob_string(std::string_view s = {}) override {add(s, types::blob_string);} - void on_streamed_string_part(std::string_view s = {}) override {add(s, types::streamed_string_part);} + void on_simple_string(std::string_view s) override { add(s, resp3::type::simple_string); } + void on_simple_error(std::string_view s) override { add(s, resp3::type::simple_error); } + void on_number(std::string_view s) override {add(s, resp3::type::number);} + void on_double(std::string_view s) override {add(s, resp3::type::double_type);} + void on_bool(std::string_view s) override {add(s, resp3::type::boolean);} + void on_big_number(std::string_view s) override {add(s, resp3::type::big_number);} + void on_null() override {add({}, resp3::type::null);} + void on_blob_error(std::string_view s = {}) override {add(s, resp3::type::blob_error);} + void on_verbatim_string(std::string_view s = {}) override {add(s, resp3::type::verbatim_string);} + void on_blob_string(std::string_view s = {}) override {add(s, resp3::type::blob_string);} + void on_streamed_string_part(std::string_view s = {}) override {add(s, resp3::type::streamed_string_part);} void clear() { result.clear(); depth_ = 0;} auto size() const { return result.size(); } void pop() override { --depth_; } diff --git a/include/aedis/detail/write.hpp b/include/aedis/detail/write.hpp index 8ddaf462..18309d6d 100644 --- a/include/aedis/detail/write.hpp +++ b/include/aedis/detail/write.hpp @@ -10,9 +10,7 @@ #include #include -#include - -#include "read.hpp" +#include #include @@ -22,7 +20,7 @@ template std::size_t write( SyncWriteStream& stream, - request& req, + pipeline& req, boost::system::error_code& ec) { static_assert(boost::beast::is_sync_write_stream::value, @@ -34,7 +32,7 @@ write( template std::size_t write( SyncWriteStream& stream, - request& req) + pipeline& req) { static_assert(boost::beast::is_sync_write_stream::value, "SyncWriteStream type requirements not met"); @@ -53,25 +51,25 @@ template net::awaitable async_write_all( AsyncReadWriteStream& socket, - request_queue& reqs, + std::queue& reqs, boost::system::error_code& ec) { // Commands like unsubscribe have a push response so we do not - // have to wait for a response before sending a new request. - while (!std::empty(reqs) && !reqs.front().sent) { - reqs.front().sent = true; - auto buffer = net::buffer(reqs.front().req.payload); + // have to wait for a response before sending a new pipeline. + while (!std::empty(reqs) && !reqs.front().writing) { + reqs.front().writing = true; + auto buffer = net::buffer(reqs.front().payload); co_await async_write( socket, buffer, net::redirect_error(net::use_awaitable, ec)); if (ec) { - reqs.front().sent = false; + reqs.front().writing = false; co_return; } - if (!std::empty(reqs.front().req.cmds)) + if (!std::empty(reqs.front().cmds)) break; reqs.pop(); diff --git a/include/aedis/impl/commands.ipp b/include/aedis/impl/commands.ipp index 4a9812f5..3b544f68 100644 --- a/include/aedis/impl/commands.ipp +++ b/include/aedis/impl/commands.ipp @@ -5,15 +5,15 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include namespace aedis { -#define EXPAND_COMMAND_CASE(x) case commands::x: return #x +#define EXPAND_COMMAND_CASE(x) case command::x: return #x -std::string to_string(commands c) +std::string to_string(command c) { switch (c) { EXPAND_COMMAND_CASE(append); @@ -66,7 +66,7 @@ std::string to_string(commands c) } } -std::ostream& operator<<(std::ostream& os, aedis::commands c) +std::ostream& operator<<(std::ostream& os, aedis::command c) { os << to_string(c); return os; diff --git a/include/aedis/impl/connection.ipp b/include/aedis/impl/connection.ipp index f0bd31ea..a5bdf54c 100644 --- a/include/aedis/impl/connection.ipp +++ b/include/aedis/impl/connection.ipp @@ -6,6 +6,7 @@ */ #include +#include #include namespace aedis { diff --git a/include/aedis/impl/src.hpp b/include/aedis/impl/src.hpp index fd1c72df..4e7fe02d 100644 --- a/include/aedis/impl/src.hpp +++ b/include/aedis/impl/src.hpp @@ -5,7 +5,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include diff --git a/include/aedis/impl/types.ipp b/include/aedis/impl/type.ipp similarity index 50% rename from include/aedis/impl/types.ipp rename to include/aedis/impl/type.ipp index 36e3c0ef..42d0a172 100644 --- a/include/aedis/impl/types.ipp +++ b/include/aedis/impl/type.ipp @@ -5,17 +5,17 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include -namespace aedis { +namespace aedis { namespace resp3 { -#define EXPAND_TYPE_CASE(x) case types::x: return #x +#define EXPAND_TYPE_CASE(x) case resp3::type::x: return #x -std::string to_string(types type) +std::string to_string(type t) { - switch (type) { + switch (t) { EXPAND_TYPE_CASE(array); EXPAND_TYPE_CASE(push); EXPAND_TYPE_CASE(set); @@ -37,33 +37,34 @@ std::string to_string(types type) } } -types to_type(char c) +type to_type(char c) { switch (c) { - case '!': return types::blob_error; - case '=': return types::verbatim_string; - case '$': return types::blob_string; - case ';': return types::streamed_string_part; - case '-': return types::simple_error; - case ':': return types::number; - case ',': return types::double_type; - case '#': return types::boolean; - case '(': return types::big_number; - case '+': return types::simple_string; - case '_': return types::null; - case '>': return types::push; - case '~': return types::set; - case '*': return types::array; - case '|': return types::attribute; - case '%': return types::map; - default: return types::invalid; + case '!': return type::blob_error; + case '=': return type::verbatim_string; + case '$': return type::blob_string; + case ';': return type::streamed_string_part; + case '-': return type::simple_error; + case ':': return type::number; + case ',': return type::double_type; + case '#': return type::boolean; + case '(': return type::big_number; + case '+': return type::simple_string; + case '_': return type::null; + case '>': return type::push; + case '~': return type::set; + case '*': return type::array; + case '|': return type::attribute; + case '%': return type::map; + default: return type::invalid; } } +} // resp3 } // aedis -std::ostream& operator<<(std::ostream& os, aedis::types type) +std::ostream& operator<<(std::ostream& os, aedis::resp3::type t) { - os << to_string(type); + os << to_string(t); return os; } diff --git a/include/aedis/request.hpp b/include/aedis/pipeline.hpp similarity index 68% rename from include/aedis/request.hpp rename to include/aedis/pipeline.hpp index 74e2b2f8..19f386dc 100644 --- a/include/aedis/request.hpp +++ b/include/aedis/pipeline.hpp @@ -16,7 +16,7 @@ #include #include -#include "commands.hpp" +#include "command.hpp" #include "net.hpp" namespace aedis { namespace resp { @@ -134,111 +134,108 @@ void assemble(std::string& ret, std::string_view cmd, std::string_view key) /** A class to compose redis requests * - * A request is composed of one or more redis commands and is refered - * to in the redis documentation as a pipeline, see + * A pipeline is composed of one or more redis commands and is + * refered to in the redis documentation as a pipeline, see * https://redis.io/topics/pipelining. * * The protocol version suported is RESP3, see * https://github.com/antirez/RESP3/blob/74adea588783e463c7e84793b325b088fe6edd1c/spec.md */ -class request { +class pipeline { public: std::string payload; - std::queue cmds; + std::queue cmds; + + // Helper member that is set to true just before the pipeline is + // writen to the socket and to false when the write operation + // completes. + bool writing = false; public: /// Return the size of the pipeline. i.e. how many commands it /// contians. auto size() const noexcept - { - return std::size(cmds); - } + { return std::size(cmds); } auto payload_size() const noexcept - { - return std::size(payload); - } + { return std::size(payload); } - bool empty() const noexcept { return std::empty(payload); }; + bool empty() const noexcept + { return std::empty(payload); }; - /// Clears the request. + /// Clears the pipeline. void clear() { payload.clear(); cmds = {}; } - /// Adds ping to the request, see https://redis.io/commands/bgrewriteaof void ping() { resp::assemble(payload, "PING"); - cmds.push(commands::ping); + cmds.push(command::ping); } - /// Adds quit to the request, see https://redis.io/commands/quit void quit() { resp::assemble(payload, "QUIT"); - cmds.push(commands::quit); + cmds.push(command::quit); } - /// Adds multi to the request, see https://redis.io/commands/multi void multi() { resp::assemble(payload, "MULTI"); - cmds.push(commands::multi); + cmds.push(command::multi); } - /// Adds exec to the request, see https://redis.io/commands/exec void exec() { resp::assemble(payload, "EXEC"); - cmds.push(commands::exec); + cmds.push(command::exec); } - /// Adds incr to the request, see https://redis.io/commands/incr void incr(std::string_view key) { resp::assemble(payload, "INCR", key); - cmds.push(commands::incr); + cmds.push(command::incr); } - /// Adds auth to the request, see https://redis.io/commands/bgrewriteaof + /// Adds auth to the pipeline, see https://redis.io/commands/bgrewriteaof void auth(std::string_view pwd) { resp::assemble(payload, "AUTH", pwd); - cmds.push(commands::auth); + cmds.push(command::auth); } - /// Adds bgrewriteaof to the request, see https://redis.io/commands/bgrewriteaof + /// Adds bgrewriteaof to the pipeline, see https://redis.io/commands/bgrewriteaof void bgrewriteaof() { resp::assemble(payload, "BGREWRITEAOF"); - cmds.push(commands::bgrewriteaof); + cmds.push(command::bgrewriteaof); } - /// Adds role to the request, see https://redis.io/commands/role + /// Adds role to the pipeline, see https://redis.io/commands/role void role() { resp::assemble(payload, "ROLE"); - cmds.push(commands::role); + cmds.push(command::role); } - /// Adds bgsave to the request, see //https://redis.io/commands/bgsave + /// Adds bgsave to the pipeline, see //https://redis.io/commands/bgsave void bgsave() { resp::assemble(payload, "BGSAVE"); - cmds.push(commands::bgsave); + cmds.push(command::bgsave); } - /// Adds ping to the request, see https://redis.io/commands/flushall + /// Adds ping to the pipeline, see https://redis.io/commands/flushall void flushall() { resp::assemble(payload, "FLUSHALL"); - cmds.push(commands::flushall); + cmds.push(command::flushall); } - /// Adds ping to the request, see https://redis.io/commands/lpop + /// Adds ping to the pipeline, see https://redis.io/commands/lpop void lpop(std::string_view key, int count = 1) { //if (count == 1) { @@ -253,61 +250,61 @@ public: // std::cend(par)); //} - cmds.push(commands::lpop); + cmds.push(command::lpop); } - /// Adds ping to the request, see https://redis.io/commands/subscribe + /// Adds ping to the pipeline, see https://redis.io/commands/subscribe void subscribe(std::string_view key) { // The response to this command is a push. resp::assemble(payload, "SUBSCRIBE", key); } - /// Adds ping to the request, see https://redis.io/commands/unsubscribe + /// Adds ping to the pipeline, see https://redis.io/commands/unsubscribe void unsubscribe(std::string_view key) { // The response to this command is a push. resp::assemble(payload, "UNSUBSCRIBE", key); } - /// Adds ping to the request, see https://redis.io/commands/get + /// Adds ping to the pipeline, see https://redis.io/commands/get void get(std::string_view key) { resp::assemble(payload, "GET", key); - cmds.push(commands::get); + cmds.push(command::get); } - /// Adds ping to the request, see https://redis.io/commands/keys + /// Adds ping to the pipeline, see https://redis.io/commands/keys void keys(std::string_view pattern) { resp::assemble(payload, "KEYS", pattern); - cmds.push(commands::keys); + cmds.push(command::keys); } - /// Adds ping to the request, see https://redis.io/commands/hello + /// Adds ping to the pipeline, see https://redis.io/commands/hello void hello(std::string_view version = "3") { resp::assemble(payload, "HELLO", version); - cmds.push(commands::hello); + cmds.push(command::hello); } - /// Adds ping to the request, see https://redis.io/commands/sentinel + /// Adds ping to the pipeline, see https://redis.io/commands/sentinel void sentinel(std::string_view arg, std::string_view name) { auto par = {name}; resp::assemble(payload, "SENTINEL", {arg}, std::cbegin(par), std::cend(par)); - cmds.push(commands::sentinel); + cmds.push(command::sentinel); } - /// Adds ping to the request, see https://redis.io/commands/append + /// Adds ping to the pipeline, see https://redis.io/commands/append void append(std::string_view key, std::string_view msg) { auto par = {msg}; resp::assemble(payload, "APPEND", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::append); + cmds.push(command::append); } - /// Adds ping to the request, see https://redis.io/commands/bitcount + /// Adds ping to the pipeline, see https://redis.io/commands/bitcount void bitcount(std::string_view key, int start = 0, int end = -1) { auto const start_str = std::to_string(start); @@ -319,25 +316,25 @@ public: , {key} , std::cbegin(par) , std::cend(par)); - cmds.push(commands::bitcount); + cmds.push(command::bitcount); } - /// Adds ping to the request, see https://redis.io/commands/rpush + /// Adds ping to the pipeline, see https://redis.io/commands/rpush template void rpush(std::string_view key, Iter begin, Iter end) { resp::assemble(payload, "RPUSH", {key}, begin, end); - cmds.push(commands::rpush); + cmds.push(command::rpush); } - /// Adds ping to the request, see https://redis.io/commands/rpush + /// Adds ping to the pipeline, see https://redis.io/commands/rpush template void rpush( std::string_view key, std::initializer_list v) { return rpush(key, std::cbegin(v), std::cend(v)); } - /// Adds ping to the request, see https://redis.io/commands/rpush + /// Adds ping to the pipeline, see https://redis.io/commands/rpush template void rpush( std::string_view key, Range const& v) { @@ -346,39 +343,38 @@ public: rpush(key, cbegin(v), cend(v)); } - /// Adds ping to the request, see https://redis.io/commands/lpush + /// Adds ping to the pipeline, see https://redis.io/commands/lpush template void lpush(std::string_view key, Iter begin, Iter end) { resp::assemble(payload, "LPUSH", {key}, begin, end); - cmds.push(commands::lpush); + cmds.push(command::lpush); } - /// Adds ping to the request, see https://redis.io/commands/psubscribe void psubscribe( std::initializer_list l) { std::initializer_list dummy = {}; resp::assemble(payload, "PSUBSCRIBE", l, std::cbegin(dummy), std::cend(dummy)); } - /// Adds ping to the request, see https://redis.io/commands/publish + /// Adds ping to the pipeline, see https://redis.io/commands/publish void publish(std::string_view key, std::string_view msg) { auto par = {msg}; resp::assemble(payload, "PUBLISH", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::publish); + cmds.push(command::publish); } - /// Adds ping to the request, see https://redis.io/commands/set + /// Adds ping to the pipeline, see https://redis.io/commands/set void set(std::string_view key, std::initializer_list args) { resp::assemble(payload, "SET", {key}, std::cbegin(args), std::cend(args)); - cmds.push(commands::set); + cmds.push(command::set); } // TODO: Find a way to assert the value type is a pair. - /// Adds ping to the request, see https://redis.io/commands/hset + /// Adds ping to the pipeline, see https://redis.io/commands/hset template void hset(std::string_view key, Range const& r) { @@ -387,56 +383,56 @@ public: using std::cbegin; using std::cend; resp::assemble(payload, "HSET", {key}, std::cbegin(r), std::cend(r), 2); - cmds.push(commands::hset); + cmds.push(command::hset); } - /// Adds ping to the request, see https://redis.io/commands/hincrby + /// Adds ping to the pipeline, see https://redis.io/commands/hincrby void hincrby(std::string_view key, std::string_view field, int by) { auto by_str = std::to_string(by); std::initializer_list par {field, by_str}; resp::assemble(payload, "HINCRBY", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::hincrby); + cmds.push(command::hincrby); } - /// Adds ping to the request, see https://redis.io/commands/hkeys + /// Adds ping to the pipeline, see https://redis.io/commands/hkeys void hkeys(std::string_view key) { auto par = {""}; resp::assemble(payload, "HKEYS", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::hkeys); + cmds.push(command::hkeys); } - /// Adds ping to the request, see https://redis.io/commands/hlen + /// Adds ping to the pipeline, see https://redis.io/commands/hlen void hlen(std::string_view key) { resp::assemble(payload, "HLEN", {key}); - cmds.push(commands::hlen); + cmds.push(command::hlen); } - /// Adds ping to the request, see https://redis.io/commands/hgetall + /// Adds ping to the pipeline, see https://redis.io/commands/hgetall void hgetall(std::string_view key) { resp::assemble(payload, "HGETALL", {key}); - cmds.push(commands::hgetall); + cmds.push(command::hgetall); } - /// Adds ping to the request, see https://redis.io/commands/hvals + /// Adds ping to the pipeline, see https://redis.io/commands/hvals void hvals( std::string_view key) { resp::assemble(payload, "HVALS", {key}); - cmds.push(commands::hvals); + cmds.push(command::hvals); } - /// Adds ping to the request, see https://redis.io/commands/hget + /// Adds ping to the pipeline, see https://redis.io/commands/hget void hget(std::string_view key, std::string_view field) { auto par = {field}; resp::assemble(payload, "HGET", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::hget); + cmds.push(command::hget); } - /// Adds ping to the request, see https://redis.io/commands/hmget + /// Adds ping to the pipeline, see https://redis.io/commands/hmget void hmget( std::string_view key, std::initializer_list fields) @@ -447,10 +443,10 @@ public: , std::cbegin(fields) , std::cend(fields)); - cmds.push(commands::hmget); + cmds.push(command::hmget); } - /// Adds ping to the request, see https://redis.io/commands/hdel + /// Adds ping to the pipeline, see https://redis.io/commands/hdel void hdel(std::string_view key, std::initializer_list fields) @@ -462,36 +458,36 @@ public: std::cbegin(fields), std::cend(fields)); - cmds.push(commands::hdel); + cmds.push(command::hdel); } - /// Adds ping to the request, see https://redis.io/commands/expire + /// Adds ping to the pipeline, see https://redis.io/commands/expire void expire(std::string_view key, int secs) { auto const str = std::to_string(secs); std::initializer_list par {str}; resp::assemble(payload, "EXPIRE", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::expire); + cmds.push(command::expire); } - /// Adds ping to the request, see https://redis.io/commands/zadd + /// Adds ping to the pipeline, see https://redis.io/commands/zadd void zadd(std::string_view key, int score, std::string_view value) { auto const score_str = std::to_string(score); std::initializer_list par = {score_str, value}; resp::assemble(payload, "ZADD", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::zadd); + cmds.push(command::zadd); } - /// Adds ping to the request, see https://redis.io/commands/zadd + /// Adds ping to the pipeline, see https://redis.io/commands/zadd template void zadd(std::initializer_list key, Range const& r) { resp::assemble(payload, "ZADD", key, std::cbegin(r), std::cend(r), 2); - cmds.push(commands::zadd); + cmds.push(command::zadd); } - /// Adds ping to the request, see https://redis.io/commands/zrange + /// Adds ping to the pipeline, see https://redis.io/commands/zrange void zrange(std::string_view key, int min = 0, int max = -1) { auto const min_str = std::to_string(min); @@ -499,10 +495,10 @@ public: std::initializer_list par {min_str, max_str}; resp::assemble(payload, "ZRANGE", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::zrange); + cmds.push(command::zrange); } - /// Adds ping to the request, see https://redis.io/commands/zrangebyscore + /// Adds ping to the pipeline, see https://redis.io/commands/zrangebyscore void zrangebyscore(std::string_view key, int min, int max) { auto max_str = std::string {"inf"}; @@ -512,10 +508,10 @@ public: auto const min_str = std::to_string(min); auto par = {min_str , max_str}; resp::assemble(payload, "ZRANGEBYSCORE", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::zrangebyscore); + cmds.push(command::zrangebyscore); } - /// Adds ping to the request, see https://redis.io/commands/zremrangebyscore + /// Adds ping to the pipeline, see https://redis.io/commands/zremrangebyscore void zremrangebyscore( std::string_view key, @@ -524,53 +520,53 @@ public: { auto par = {min, max}; resp::assemble(payload, "ZREMRANGEBYSCORE", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::zremrangebyscore); + cmds.push(command::zremrangebyscore); } - /// Adds ping to the request, see https://redis.io/commands/lrange + /// Adds ping to the pipeline, see https://redis.io/commands/lrange void lrange(std::string_view key, int min = 0, int max = -1) { auto const min_str = std::to_string(min); auto const max_str = std::to_string(max); std::initializer_list par {min_str, max_str}; resp::assemble(payload, "LRANGE", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::lrange); + cmds.push(command::lrange); } - /// Adds ping to the request, see https://redis.io/commands/ltrim + /// Adds ping to the pipeline, see https://redis.io/commands/ltrim void ltrim(std::string_view key, int min = 0, int max = -1) { auto const min_str = std::to_string(min); auto const max_str = std::to_string(max); std::initializer_list par {min_str, max_str}; resp::assemble(payload, "LTRIM", {key}, std::cbegin(par), std::cend(par)); - cmds.push(commands::ltrim); + cmds.push(command::ltrim); } // TODO: Overload for vector del. - /// Adds ping to the request, see https://redis.io/commands/del + /// Adds ping to the pipeline, see https://redis.io/commands/del void del(std::string_view key) { resp::assemble(payload, "DEL", key); - cmds.push(commands::del); + cmds.push(command::del); } - /// Adds ping to the request, see https://redis.io/commands/llen + /// Adds ping to the pipeline, see https://redis.io/commands/llen void llen(std::string_view key) { resp::assemble(payload, "LLEN", key); - cmds.push(commands::llen); + cmds.push(command::llen); } - /// Adds ping to the request, see https://redis.io/commands/sadd + /// Adds ping to the pipeline, see https://redis.io/commands/sadd template void sadd(std::string_view key, Iter begin, Iter end) { resp::assemble(payload, "SADD", {key}, begin, end); - cmds.push(commands::sadd); + cmds.push(command::sadd); } - /// Adds ping to the request, see https://redis.io/commands/sadd + /// Adds ping to the pipeline, see https://redis.io/commands/sadd template void sadd(std::string_view key, Range const& r) { @@ -579,32 +575,32 @@ public: sadd(key, cbegin(r), cend(r)); } - /// Adds ping to the request, see https://redis.io/commands/smembers + /// Adds ping to the pipeline, see https://redis.io/commands/smembers void smembers(std::string_view key) { resp::assemble(payload, "SMEMBERS", key); - cmds.push(commands::smembers); + cmds.push(command::smembers); } - /// Adds ping to the request, see https://redis.io/commands/scard + /// Adds ping to the pipeline, see https://redis.io/commands/scard void scard(std::string_view key) { resp::assemble(payload, "SCARD", key); - cmds.push(commands::scard); + cmds.push(command::scard); } - /// Adds ping to the request, see https://redis.io/commands/scard + /// Adds ping to the pipeline, see https://redis.io/commands/scard void scard(std::string_view key, std::initializer_list l) { resp::assemble(payload, "SDIFF", {key}, std::cbegin(l), std::cend(l)); - cmds.push(commands::scard); + cmds.push(command::scard); } - /// Adds ping to the request, see https://redis.io/commands/client_id + /// Adds ping to the pipeline, see https://redis.io/commands/client_id void client_id(std::string_view parameters) { resp::assemble(payload, "CLIENT ID", {parameters}); - cmds.push(commands::client_id); + cmds.push(command::client_id); } }; diff --git a/include/aedis/receiver_base.hpp b/include/aedis/receiver_base.hpp index 5678dcc1..3d292dd0 100644 --- a/include/aedis/receiver_base.hpp +++ b/include/aedis/receiver_base.hpp @@ -10,9 +10,8 @@ #include #include -#include "types.hpp" -#include "request.hpp" -#include "resp_types.hpp" +#include "type.hpp" +#include "pipeline.hpp" namespace aedis { @@ -167,13 +166,13 @@ public: virtual void on_push(array_type& v) noexcept { } /// Callback for simple error. - virtual void on_simple_error(commands cmd, simple_error_type& v) noexcept { } + virtual void on_simple_error(command cmd, simple_error_type& v) noexcept { } /// Callback for blob error. - virtual void on_blob_error(commands cmd, blob_error_type& v) noexcept { } + virtual void on_blob_error(command cmd, blob_error_type& v) noexcept { } /// Callback from null responses. - virtual void on_null(commands cmd) noexcept { } + virtual void on_null(command cmd) noexcept { } /// Receives a transaction virtual void diff --git a/include/aedis/resp_types.hpp b/include/aedis/type.hpp similarity index 68% rename from include/aedis/resp_types.hpp rename to include/aedis/type.hpp index 1e9b86b3..0f3a7235 100644 --- a/include/aedis/resp_types.hpp +++ b/include/aedis/type.hpp @@ -7,12 +7,39 @@ #pragma once +#include #include #include -#include "commands.hpp" +#include "command.hpp" -namespace aedis { +namespace aedis { namespace resp3 { + +enum class type +{ array +, push +, set +, map +, attribute +, simple_string +, simple_error +, number +, double_type +, boolean +, big_number +, null +, blob_error +, verbatim_string +, blob_string +, streamed_string_part +, invalid +}; + +type to_type(char c); + +} // resp3 + +// TODO: Move everything below to namespace resp3. template using basic_array_type = std::vector; @@ -39,10 +66,13 @@ using streamed_string_part_type = std::string; struct transaction_element { int depth; - types type; + resp3::type type; int expected_size = -1; - commands command = commands::unknown; + command cmd = command::unknown; std::vector value; }; } // aedis + +std::ostream& operator<<(std::ostream& os, aedis::resp3::type t); + diff --git a/include/aedis/types.hpp b/include/aedis/types.hpp deleted file mode 100644 index c86f7a8e..00000000 --- a/include/aedis/types.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* 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/. - */ - -#pragma once - -#include - -namespace aedis { - -enum class types -{ array -, push -, set -, map -, attribute -, simple_string -, simple_error -, number -, double_type -, boolean -, big_number -, null -, blob_error -, verbatim_string -, blob_string -, streamed_string_part -, invalid -}; - -types to_type(char c); - -} // aedis - -std::ostream& operator<<(std::ostream& os, aedis::types t); - diff --git a/tests/general.cpp b/tests/general.cpp index eee4a831..b9cefd7c 100644 --- a/tests/general.cpp +++ b/tests/general.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "test_stream.hpp" @@ -92,7 +93,7 @@ public: conn_->send(f); } - void on_simple_error(commands cmd, simple_error_type& v) noexcept override + void on_simple_error(command cmd, simple_error_type& v) noexcept override { std::cout << v << std::endl; } @@ -208,12 +209,12 @@ public: ping_receiver(std::shared_ptr conn) : conn_{conn} { } void on_hello(array_type& v) noexcept override - { conn_->send([this](auto& req) { req.ping(); }); } + { conn_->ping(); } void on_ping(simple_string_type& s) noexcept override { check_equal(s, {"PONG"}, "ping"); - conn_->send([this](auto& req) { req.quit(); }); + conn_->quit(); } void on_quit(simple_string_type& s) noexcept override @@ -313,20 +314,20 @@ public: void on_transaction(std::vector& result) noexcept override { - check_equal(result[0].command, commands::ping, "transaction ping (command)"); + check_equal(result[0].cmd, command::ping, "transaction ping (command)"); check_equal(result[0].depth, 1, "transaction (depth)"); - check_equal(result[0].type, types::simple_string, "transaction (type)"); + check_equal(result[0].type, resp3::type::simple_string, "transaction (type)"); check_equal(result[0].expected_size, 1, "transaction (size)"); - check_equal(result[1].command, commands::ping, "transaction incr (command)"); + check_equal(result[1].cmd, command::ping, "transaction incr (command)"); check_equal(result[1].depth, 1, "transaction (depth)"); - check_equal(result[1].type, types::simple_string, "transaction (typ)e"); + check_equal(result[1].type, resp3::type::simple_string, "transaction (typ)e"); check_equal(result[1].expected_size, 1, "transaction (size)"); // See note above - //check_equal(result[2].command, commands::publish, "transaction publish (command)"); + //check_equal(result[2].command, command::publish, "transaction publish (command)"); //check_equal_number(result[2].depth, 1, "transaction (depth)"); - //check_equal_number(result[2].type, types::number, "transaction (type)"); + //check_equal_number(result[2].type, resp3::type::number, "transaction (type)"); //check_equal_number(result[2].expected_size, 1, "transaction (size)"); result.clear(); } @@ -364,7 +365,7 @@ test_list(net::ip::tcp::resolver::results_type const& results) { std::vector list {1 ,2, 3, 4, 5, 6}; - request p; + pipeline p; p.hello("3"); p.flushall(); p.rpush("a", list); @@ -444,7 +445,7 @@ test_set(net::ip::tcp::resolver::results_type const& results) tcp_socket socket {ex}; co_await async_connect(socket, results); - request p; + pipeline p; p.hello("3"); p.flushall(); p.set("s", {test_bulk1});