-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_hiredispool.cpp
66 lines (55 loc) · 1.27 KB
/
test_hiredispool.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
58
59
60
61
62
63
64
65
66
#include <pthread.h>
#include <time.h>
#include <unistd.h>
#include "hiredispool.h"
#include "log.h"
#include "hiredis/hiredis.h"
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
LOG_CONFIG c = {
-9,
LOG_DEST_FILES,
"log/test_hiredispool.log",
"test_hiredispool",
0,
1
};
log_set_config(&c);
REDIS_ENDPOINT endpoints[4] = {
{ "127.0.0.1", 6379 },
{ "127.0.0.1", 6380 },
{ "127.0.0.1", 6381 },
{ "127.0.0.1", 6382 },
};
REDIS_CONFIG conf = {
(REDIS_ENDPOINT*)&endpoints,
4,
10000,
5000,
20,
1,
};
REDIS_INSTANCE* inst;
if (redis_pool_create(&conf, &inst) < 0)
return -1;
//sleep(5);
REDIS_SOCKET* sock;
if ((sock = redis_get_socket(inst)) == NULL) {
redis_pool_destroy(inst);
return -1;
}
//sleep(5);
redisReply* reply;
if ((reply = (redisReply*)redis_command(sock, inst, "PING")) == NULL) {
redis_release_socket(inst, sock);
redis_pool_destroy(inst);
return -1;
}
log_(L_INFO|L_CONS, "PING: %s", reply->str);
freeReplyObject(reply);
redis_release_socket(inst, sock);
redis_pool_destroy(inst);
return 0;
}