-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_query.cpp
123 lines (93 loc) · 3.23 KB
/
test_query.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include "hiredis.h"
using namespace std;
void process_reply(redisContext *c, redisReply *reply, int &count){
if (reply && reply->type == REDIS_REPLY_ARRAY){
for (int i=0;i<reply->elements;i++){
process_reply(c, reply->element[i], count);
}
} else if (reply && reply->type == REDIS_REPLY_STRING){
count++;
cout << "(" << count << ") " << reply->str << endl;
} else if (reply && reply->type == REDIS_REPLY_ERROR){
cout << reply->str << endl;
} else {
cout << "Error: " << c->errstr << endl;
}
return;
}
int main(int argc, char **argv){
string cmdstr = "reventis.query";
string key = "myevents";
double x1, y1, x2, y2;
string startdatetime, enddatetime;
int count = 0;
string cmdlinestr = cmdstr + " %s %f %f %f %f %s %s";
redisContext *c = redisConnect("localhost", 6379);
if (c == NULL || c->err){
if (c) cout << "Error: " << c->errstr << endl;
else cout << "Unable to allocate redis context" << endl;
}
redisReply *reply;
x1 = -72.338000;
x2 = -72.330000;
y1 = 41.571000;
y2 = 41.576000;
startdatetime = "2019-12-01T12:00";
enddatetime = "2019-12-01T16:00";
cout << "query: " << cmdstr << " " << key << " " << x1 << " " << x2 << " " << y1 << " " << y2 << " "
<< startdatetime << " " << enddatetime << " " << endl;
reply = (redisReply*)redisCommand(c, cmdlinestr.c_str(), key.c_str(), x1, x2, y1, y2,
startdatetime.c_str(), enddatetimestr.c_str());
count = 0;
process_reply(c, reply, count);
freeReplyObject(reply);
cout << "Total = " << count << endl << endl;
x1 = -72.257400;
x2 = -72.248800;
y1 = 41.806490;
y2 = 41.809360;
startdatetime = "2019-12-04T09:00";
enddatetime = "2019-12-04T18:00";
cout << "query: " << cmdstr << " " << key << " " << x1 << " " << x2 << " " << y1 << " " << y2
<< startdatetime << " " << enddatetime << endl;
reply = (redisReply*)redisCommand(c, cmdlinestr.c_str(), key.c_str(), x1, x2, y1, y2,
startdatetime.c_str(), enddatetime.c_str());
count = 0;
process_reply(c, reply, count);
freeReplyObject(reply);
cout << "Total = " << count << endl << endl;
x1 = -72.218815;
x2 = -72.217520;
y1 = 41.719640;
y2 = 41.720690;
startdatetime = "2019-10-09T12:00";
enddatetime = "2019-10-09T18:00";
cout << "query: " << cmdstr << " " << key << " " << x1 << " " << x2 << " " << y1 << " " << y2
<< startdatetime << " " << enddatetime << endl;
reply = (redisReply*)redisCommand(c, cmdlinestr.c_str(), key.c_str(), x1, x2, y1, y2,
startdatetime.c_str(), enddatetime.c_str());
count = 0;
process_reply(c, reply, count);
freeReplyObject(reply);
cout << "Total = " << count << endl << endl;
x1 = -73.514076;
x2 = -71.793121;
y1 = 41.187130;
y2 = 42.036561;
startdatetime = "2019-01-01T12:00";
enddatetime = "2020-01-01T12:00";
cout << "query: " << cmdstr << " " << key << " " << x1 << " " << x2 << " " << y1 << " " << y2
<< startdatetime << " " << enddatetime << endl;
reply = (redisReply*)redisCommand(c, cmdlinestr.c_str(), key.c_str(), x1, x2, y1, y2,
startdatetime.c_str(), enddatetime.c_str());
count = 0;
process_reply(c, reply, count);
freeReplyObject(reply);
cout << "Total = " << count << endl << endl;
redisFree(c);
return 0;
}