forked from Cylix/cpp_redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis_client.cpp
More file actions
33 lines (25 loc) · 751 Bytes
/
redis_client.cpp
File metadata and controls
33 lines (25 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cpp_redis/cpp_redis>
#include <signal.h>
#include <iostream>
volatile std::atomic_bool should_exit(false);
cpp_redis::redis_client client;
void
sigint_handler(int) {
std::cout << "disconnected (sigint handler)" << std::endl;
client.disconnect();
}
int
main(void) {
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
should_exit = true;
});
client.connect();
client.send({"SET", "hello", "world"});
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});
signal(SIGINT, &sigint_handler);
while (not should_exit);
return 0;
}