diff --git a/examples/async_basic.cpp b/examples/async_basic.cpp index 255ee126..da716799 100644 --- a/examples/async_basic.cpp +++ b/examples/async_basic.cpp @@ -17,12 +17,12 @@ void f(request& req) req.quit(); } -class receiver : public receiver_base { +class myreceiver : public receiver_base { private: std::shared_ptr conn_; public: - receiver(std::shared_ptr conn) : conn_{conn} { } + myreceiver(std::shared_ptr conn) : conn_{conn} { } void on_hello(resp::array_type& v) noexcept override { conn_->send(f); } @@ -40,8 +40,8 @@ public: int main() { net::io_context ioc {1}; - auto conn = std::make_shared(ioc); - receiver recv{conn}; + auto conn = std::make_shared(ioc.get_executor()); + myreceiver recv{conn}; conn->start(recv); ioc.run(); } diff --git a/include/aedis/connection.hpp b/include/aedis/connection.hpp index 8841ea54..e038e187 100644 --- a/include/aedis/connection.hpp +++ b/include/aedis/connection.hpp @@ -19,10 +19,17 @@ namespace aedis { +/** A class that keeps a connection to the redis server. +*/ class connection : public std::enable_shared_from_this { public: + /** Redis server configuration. + */ struct config { + // Redis host. std::string host; + + // Redis port. std::string port; }; @@ -39,12 +46,17 @@ private: net::awaitable worker_coro(receiver_base& recv); public: + /// Contructs a connection. connection( - net::io_context& ioc, + net::any_io_executor const& ioc, config const& conf = config {"127.0.0.1", "6379"}); + /// Stablishes the connection with the redis server. void start(receiver_base& recv); + /// Adds commands to the ouput queue. The Filler signature must be + /// + /// void f(request& req) template void send(Filler filler) { queue_writer(reqs_, filler, timer_); } diff --git a/include/aedis/impl/connection.ipp b/include/aedis/impl/connection.ipp index fca72427..8d4ca359 100644 --- a/include/aedis/impl/connection.ipp +++ b/include/aedis/impl/connection.ipp @@ -10,7 +10,7 @@ namespace aedis { -connection::connection(net::io_context& ioc, config const& conf) +connection::connection(net::any_io_executor const& ioc, config const& conf) : timer_{ioc} , socket_{ioc} , conf_{conf} diff --git a/include/aedis/receiver_base.hpp b/include/aedis/receiver_base.hpp index ac6f726c..e3c2ee60 100644 --- a/include/aedis/receiver_base.hpp +++ b/include/aedis/receiver_base.hpp @@ -18,10 +18,19 @@ namespace aedis { #define RECEIVER_FUNCTION_REF(name, cmd) virtual void on_##cmd(resp::name& v) noexcept { } #define RECEIVER_FUNCTION(name, cmd) virtual void on_##cmd(resp::name v) noexcept { } +/** Receiver base class. + * + * Response to redis commands via callback. + */ class receiver_base { public: + /// Receives an acl_list response. RECEIVER_FUNCTION_REF(array_type, acl_list); + + /// Receives an acl_users response. RECEIVER_FUNCTION_REF(array_type, acl_users); + + /// Receives an acl_getuser response. RECEIVER_FUNCTION_REF(array_type, acl_getuser); RECEIVER_FUNCTION_REF(array_type, acl_cat); RECEIVER_FUNCTION_REF(array_type, acl_log); diff --git a/include/aedis/request.hpp b/include/aedis/request.hpp index 40c25079..d5ea89bb 100644 --- a/include/aedis/request.hpp +++ b/include/aedis/request.hpp @@ -133,6 +133,8 @@ void assemble(std::string& ret, std::string_view cmd, std::string_view key) } // resp +/** A class that generates RESP3-commands. +*/ class request { public: std::string payload; @@ -140,42 +142,50 @@ public: public: bool empty() const noexcept { return std::empty(payload); }; + + /// Clear the commands. void clear() { payload.clear(); cmds = {}; } + /// Adds the ping command to the request. See https://redis.io/commands/ping. void ping() { resp::assemble(payload, "PING"); cmds.push(command::ping); } + /// Adds the quit command to the request. See https://redis.io/commands/quit void quit() { resp::assemble(payload, "QUIT"); cmds.push(command::quit); } + /// Adds the multi command to the request. See https://redis.io/commands/multi void multi() { resp::assemble(payload, "MULTI"); cmds.push(command::multi); } + /// Adds the exec command to the request. See https://redis.io/commands/exec void exec() { resp::assemble(payload, "EXEC"); cmds.push(command::exec); } + /// Adds the incr to the request. See void incr(std::string_view key) { resp::assemble(payload, "INCR", key); cmds.push(command::incr); } + /// Adds the auth command to the request. See void auth(std::string_view pwd) { resp::assemble(payload, "AUTH", pwd); diff --git a/tests/general.cpp b/tests/general.cpp index 1db5e585..0daf8c53 100644 --- a/tests/general.cpp +++ b/tests/general.cpp @@ -686,7 +686,7 @@ int main(int argc, char* argv[]) co_spawn(ioc, test_list(results), net::detached); co_spawn(ioc, test_set(results), net::detached); - auto conn = std::make_shared(ioc); + auto conn = std::make_shared(ioc.get_executor()); test_receiver recv{conn}; conn->start(recv);