Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit d67ae7b

Browse files
committed
clean redis_subscriber example
1 parent f986024 commit d67ae7b

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

examples/redis_subscriber.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55

66
volatile std::atomic_bool should_exit(false);
77
cpp_redis::redis_subscriber sub;
8-
cpp_redis::redis_client client;
98

109
void
1110
sigint_handler(int) {
12-
std::cout << "disconnected (sigint handler)" << std::endl;
13-
sub.disconnect();
14-
should_exit = true;
11+
std::cout << "disconnected (sigint handler)" << std::endl;
12+
sub.disconnect();
13+
should_exit = true;
1514
}
1615

1716
int
1817
main(void) {
19-
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
20-
std::cout << "sub disconnected (disconnection handler)" << std::endl;
21-
should_exit = true;
22-
});
18+
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
19+
std::cout << "sub disconnected (disconnection handler)" << std::endl;
20+
should_exit = true;
21+
});
2322

24-
sub.connect();
25-
client.connect();
23+
sub.connect();
2624

27-
sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
28-
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
29-
});
30-
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
31-
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
32-
});
25+
sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
26+
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
27+
});
28+
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
29+
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
30+
});
3331

34-
signal(SIGINT, &sigint_handler);
35-
while (not should_exit);
32+
signal(SIGINT, &sigint_handler);
33+
while (not should_exit);
3634

37-
return 0;
35+
return 0;
3836
}

0 commit comments

Comments
 (0)