2
0
mirror of https://github.com/boostorg/redis.git synced 2026-02-20 02:52:13 +00:00

Changes in the connection class and the receiver.

This commit is contained in:
Marcelo Zimbres
2021-02-06 20:20:16 +01:00
parent 2aa3ef1be3
commit 63712da04a
15 changed files with 318 additions and 187 deletions

View File

@@ -7,31 +7,55 @@
#include <boost/asio.hpp>
#include <aedis/aedis.hpp>
#include <aedis/receiver_print.hpp>
#include <stack>
namespace net = aedis::net;
using namespace aedis;
using tcp = net::ip::tcp;
void fill1(resp::request<resp::event>& req)
enum class myevents
{ one
, two
, three
, ignore
};
void fill(resp::request<myevents>& req)
{
req.ping();
req.ping(myevents::one);
req.rpush("list", {1, 2, 3});
req.multi();
req.lrange("list");
req.exec();
req.ping();
req.ping(myevents::two);
}
class myreceiver : public receiver_base<myevents> {
private:
std::shared_ptr<connection<myevents>> conn_;
public:
using event_type = myevents;
myreceiver(std::shared_ptr<connection<myevents>> conn)
: conn_{conn}
{ }
void on_hello(myevents ev, resp::response_array::data_type& v) noexcept override
{
resp::print(v);
conn_->send(fill);
}
};
int main()
{
net::io_context ioc {1};
auto conn = std::make_shared<resp::connection<resp::event>>(ioc);
resp::receiver_base<resp::event> recv;
conn->start(recv);
conn->send(fill1);
tcp::resolver resolver{ioc};
auto const results = resolver.resolve("127.0.0.1", "6379");
auto conn = std::make_shared<connection<myevents>>(ioc);
myreceiver recv{conn};
conn->start(recv, results);
ioc.run();
}