Skip to content

Commit b0bc663

Browse files
author
hamidr
committed
Remove unnecessary lambda usage
1 parent 3e6b3f1 commit b0bc663

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

includes/async_redis/sentinel.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ namespace async_redis {
4848
static std::vector<std::string> parse_watch_master_change(const parser_t& event);
4949

5050
private:
51-
bool if_connected_do(std::function<bool ()>&& fn);
5251
void connect_all(const string& ip, int port, const connect_cb_t& connector);
5352
void check_connected(const connect_cb_t& connector, bool res);
5453
bool send(std::list<string>&& words, connection::reply_cb_t&& reply);

src/monitor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ void monitor::stream_received(ssize_t len)
239239
}
240240
}
241241

242-
// if (!(watchers_.size() || pwatchers_.size()))
243242
if (!watchers_.size() && !pwatchers_.size()) {
244243
is_watching_ = false;
245244
return;

src/sentinel.cpp

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,60 @@ void sentinel::disconnect() {
3131

3232
bool sentinel::failover(const string& clustername, connection::reply_cb_t&& reply)
3333
{
34-
return if_connected_do(
35-
[&]() -> bool {
36-
return send({std::string("sentinel failover ") + clustername}, std::move(reply));
37-
}
38-
);
34+
if (!is_connected())
35+
return false;
36+
37+
return send({std::string("sentinel failover ") + clustername}, std::move(reply));
3938
}
4039

4140
bool sentinel::ping(connection::reply_cb_t&& reply)
4241
{
43-
return if_connected_do(
44-
[&]() -> bool {
45-
return send({"ping"}, std::move(reply));
46-
}
47-
);
42+
if (!is_connected())
43+
return false;
44+
45+
return send({"ping"}, std::move(reply));
4846
}
4947

5048
bool sentinel::watch_master_change(cb_watch_master_change_t&& fn)
5149
{
52-
return if_connected_do(
53-
[&]()-> bool {
54-
using State = monitor::EventState;
55-
56-
return stream_.subscribe({"+switch-master"},
57-
[this, fn = std::move(fn)](const string& channel, parser_t event, State state) -> void
58-
{
59-
switch(state)
60-
{
61-
case State::Stream:
62-
return fn(parse_watch_master_change(event), SentinelState::Watching);
50+
if (!is_connected())
51+
return false;
6352

64-
case State::Disconnected:
65-
this->disconnect();
66-
return fn({}, SentinelState::Disconnected);
67-
break;
53+
using State = monitor::EventState;
6854

69-
default:
70-
break;
71-
}
72-
}
73-
);
55+
return stream_.subscribe({"+switch-master"},
56+
[this, fn{std::move(fn)}](const string& channel, parser_t event, State state) -> void
57+
{
58+
switch(state)
59+
{
60+
case State::Stream:
61+
return fn(parse_watch_master_change(event), SentinelState::Watching);
62+
63+
case State::Disconnected:
64+
this->disconnect();
65+
return fn({}, SentinelState::Disconnected);
66+
break;
67+
68+
default:
69+
break;
70+
}
7471
}
7572
);
7673
}
7774

7875

7976
bool sentinel::master_addr_by_name(const string& cluster_name, cb_addr_by_name_t&& cb)
8077
{
81-
return if_connected_do(
82-
[&]() -> bool {
83-
return send_master_addr_by_name(cluster_name, std::move(cb));
84-
}
85-
);
78+
if (!is_connected())
79+
return false;
80+
81+
return send_master_addr_by_name(cluster_name, std::move(cb));
8682
}
8783

8884
bool sentinel::send_master_addr_by_name(const string& cluster_name, cb_addr_by_name_t&& cb)
8985
{
9086
return this->send({string("SENTINEL get-master-addr-by-name ") + cluster_name + "\r\n"},
91-
[cb = std::move(cb)](parser_t parsed_value)
87+
[cb{std::move(cb)}](parser_t parsed_value)
9288
{
9389
using ::async_redis::parser::RespType;
9490

@@ -122,7 +118,6 @@ bool sentinel::send_master_addr_by_name(const string& cluster_name, cb_addr_by_n
122118
);
123119
}
124120

125-
// static
126121
std::vector<std::string> sentinel::parse_watch_master_change(const parser_t& event)
127122
{
128123
std::vector<string> words;
@@ -135,14 +130,6 @@ std::vector<std::string> sentinel::parse_watch_master_change(const parser_t& eve
135130
return words;
136131
}
137132

138-
bool sentinel::if_connected_do(std::function<bool ()>&& fn)
139-
{
140-
if (!is_connected())
141-
return false;
142-
143-
return fn();
144-
}
145-
146133
void sentinel::connect_all(const string& ip, int port, const connect_cb_t& connector)
147134
{
148135
auto cb = std::bind(&sentinel::check_connected, this, connector, std::placeholders::_1);

0 commit comments

Comments
 (0)