-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathRedis_Test.cpp
More file actions
75 lines (60 loc) · 1.46 KB
/
Copy pathRedis_Test.cpp
File metadata and controls
75 lines (60 loc) · 1.46 KB
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
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "hiredis.h"
#include "DB_Interface_redis.h"
#include "XLog.h"
#include "RedisResult.h"
#include <vector>
#include "RedisCommand.h"
#include <functional>
#include "DBThreadPool.h"
#include "Tools.h"
void select(DBThreadPool * pool)
{
std::shared_ptr<RedisCommand> command(new RedisCommand("lrange"));
command->pushString("t1");
command->pushString("0");
command->pushString("10");
std::shared_ptr<RedisResult> result(new RedisResult);
std::shared_ptr<DBRedisTask> task(new DBRedisTask(command, result));
task->backfunc = [](int errno_, const char * err, std::shared_ptr<RedisResult> result) {
while (result->fetch())
{
int32 value;
*result >> value;
printf("%d\n", value);
}
};
pool->addTask(task);
}
void insert(DBThreadPool * pool)
{
std::shared_ptr<RedisCommand> command(new RedisCommand("lpush"));
command->pushString("t1");
command->pushInt32(1);
command->pushInt32(22);
command->pushInt32(333);
std::shared_ptr<DBRedisTask> task(new DBRedisTask(command, std::make_shared<RedisResult>()));
task->backfunc = [pool](int errno_, const char* err, std::shared_ptr<RedisResult> result) {
select(pool);
};
pool->addTask(task);
}
int main()
{
DBConfig config;
config.device = "redis";
config.ip = "127.0.0.1";
config.port = 6379;
DBThreadPool pool(config);
pool.create(1);
insert(&pool);
while (1)
{
Tools::sleep(10);
pool.update();
}
system("pause");
return 0;
}