Skip to content

Commit

Permalink
Performance improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidr committed Jan 11, 2017
1 parent e5e25dd commit 96ea9f8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion includes/async_redis/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace async_redis

public:
using parser_t = parser::base_resp_parser::parser;
using reply_cb_t = std::function<void (parser_t)>;
using reply_cb_t = std::function<void (parser_t&)>;

connection(event_loop::event_loop_ev& event_loop);

Expand Down
2 changes: 1 addition & 1 deletion includes/async_redis/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace async_redis
};

using parser_t = parser::base_resp_parser::parser;
using watcher_cb_t = std::function<void (const string&, parser_t, EventState)>;
using watcher_cb_t = std::function<void (const string&, parser_t&, EventState)>;

monitor(event_loop::event_loop_ev &event_loop);

Expand Down
4 changes: 2 additions & 2 deletions includes/async_redis/sentinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace async_redis {

private:
int connected_ = 0;
std::unique_ptr<monitor> stream_;
std::unique_ptr<connection> conn_;
monitor stream_;
connection conn_;
};
}
5 changes: 3 additions & 2 deletions src/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@ void monitor::report_disconnect()
t2.swap(pwatchers_);

string str;
parser_t p;

for(auto &w : t1)
w.second(str, nullptr, EventState::Disconnected);
w.second(str, p, EventState::Disconnected);

for(auto &w : t2)
w.second(str, nullptr, EventState::Disconnected);
w.second(str, p, EventState::Disconnected);

disconnect();
}
Expand Down
18 changes: 9 additions & 9 deletions src/sentinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace async_redis
{
sentinel::sentinel(event_loop::event_loop_ev &event_loop)
: conn_(std::make_unique<connection>(event_loop)),
stream_(std::make_unique<monitor>(event_loop))
: conn_(event_loop),
stream_(event_loop)
{ }

bool sentinel::is_connected() const
{
return stream_->is_connected() && conn_->is_connected();
return stream_.is_connected() && conn_.is_connected();
}

bool sentinel::connect(const string& ip, int port, connect_cb_t&& connector)
Expand All @@ -25,8 +25,8 @@ bool sentinel::connect(const string& ip, int port, connect_cb_t&& connector)
}

void sentinel::disconnect() {
stream_->disconnect();
conn_->disconnect();
stream_.disconnect();
conn_.disconnect();
}

bool sentinel::failover(const string& clustername, connection::reply_cb_t&& reply)
Expand All @@ -53,7 +53,7 @@ bool sentinel::watch_master_change(cb_watch_master_change_t&& fn)
[&]()-> bool {
using State = monitor::EventState;

return stream_->subscribe({"+switch-master"},
return stream_.subscribe({"+switch-master"},
[this, fn = std::move(fn)](const string& channel, parser_t event, State state) -> void
{
switch(state)
Expand Down Expand Up @@ -147,8 +147,8 @@ void sentinel::connect_all(const string& ip, int port, const connect_cb_t& conne
{
auto cb = std::bind(&sentinel::check_connected, this, connector, std::placeholders::_1);

conn_->connect(cb, ip, port);
stream_->connect(cb, ip, port);
conn_.connect(cb, ip, port);
stream_.connect(cb, ip, port);
}

void sentinel::check_connected(const connect_cb_t& connector, bool res)
Expand All @@ -171,7 +171,7 @@ bool sentinel::send(std::list<string>&& words, connection::reply_cb_t&& reply)
cmd += " " + w;
cmd += "\r\n";

if (!conn_->send(std::move(cmd), std::move(reply))) {
if (!conn_.send(std::move(cmd), std::move(reply))) {
disconnect();
return false;
}
Expand Down

0 comments on commit 96ea9f8

Please sign in to comment.