basic_threaded.cpp
741 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
34
35
36
37
38
39
40
41
/**
* Basic asynchronous calls using redisx.
*/
#include <iostream>
#include <thread>
#include <chrono>
#include "../src/redisx.hpp"
using namespace std;
redisx::Redis rdx = {"localhost", 6379};
int main(int argc, char* argv[]) {
rdx.run();
thread setter([]() {
while(true) {
rdx.command("INCR counter");
this_thread::sleep_for(chrono::milliseconds(1));
}
});
thread getter([]() {
while(true) {
rdx.command<const string &>(
"GET counter",
[](const string& cmd, const string& value) {
cout << cmd << ": " << value << endl;
}
);
this_thread::sleep_for(chrono::milliseconds(1000));
}
});
setter.join();
getter.join();
return 0;
};