-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_RedisClient2.cpp
58 lines (45 loc) · 1.08 KB
/
test_RedisClient2.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <hiredispool/RedisClient.h>
#include <string>
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
void foo(RedisClient& client, long long c, int id)
{
client.redisCommand("SET ID%d 0", id);
long long count = -1;
for (long long i=0; i<c; ++i) {
RedisReplyPtr reply = client.redisCommand("INCR ID%d", id);
if (reply.notNull()) {
count = reply->integer;
}
}
cout << "INCR ID" << id << " to " << count << endl;
}
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
REDIS_ENDPOINT endpoints[1] = {
{ "127.0.0.1", 6379 },
//{ "127.0.0.1", 6380 },
//{ "127.0.0.1", 6381 },
};
REDIS_CONFIG conf = {
(REDIS_ENDPOINT*)&endpoints,
1,
500,
500,
20,
1,
};
RedisClient client(conf);
vector<thread> threads;
for (int i=0; i<20; ++i) {
threads.emplace_back(thread(foo, ref(client), 1000, i));
}
for(auto i=threads.begin(); i!=threads.end(); ++i) {
i->join();
}
return 0;
}