|
5 | 5 |
|
6 | 6 | volatile std::atomic_bool should_exit(false); |
7 | 7 | cpp_redis::redis_subscriber sub; |
8 | | -cpp_redis::redis_client client; |
9 | 8 |
|
10 | 9 | void |
11 | 10 | 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; |
15 | 14 | } |
16 | 15 |
|
17 | 16 | int |
18 | 17 | 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 | + }); |
23 | 22 |
|
24 | | - sub.connect(); |
25 | | - client.connect(); |
| 23 | + sub.connect(); |
26 | 24 |
|
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 | + }); |
33 | 31 |
|
34 | | - signal(SIGINT, &sigint_handler); |
35 | | - while (not should_exit); |
| 32 | + signal(SIGINT, &sigint_handler); |
| 33 | + while (not should_exit); |
36 | 34 |
|
37 | | - return 0; |
| 35 | + return 0; |
38 | 36 | } |
0 commit comments