forked from mrpi/redis-cplusplus-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cluster.cpp
More file actions
72 lines (65 loc) · 1.54 KB
/
Copy pathtest_cluster.cpp
File metadata and controls
72 lines (65 loc) · 1.54 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
#include "functions.h"
#include "../redisclient.h"
void test_cluster_dbsize(redis::client & c)
{
redis::client::int_type count;
for(size_t i=0; i < c.connections().size(); i++)
{
redis::client::int_type curSize = c.dbsize( c.connections()[i] );
cerr << "DB#" << i << " contains " << curSize << " keys" << endl;
count += curSize;
}
ASSERT_EQUAL( count, c.dbsize() );
}
boost::shared_ptr<redis::client> init_non_cluster_client()
{
const char* c_host = getenv("REDIS_HOST");
string host = "localhost";
if(c_host)
host = c_host;
return boost::shared_ptr<redis::client>( new redis::client(host) );
}
boost::shared_ptr<redis::client> init_cluster_client()
{
vector<redis::connection_data> redis_server;
const char* c_host = getenv("REDIS_HOST");
string host = "localhost";
if(c_host)
host = c_host;
{
/// DB0
redis::connection_data con;
con.host = host;
con.port = 6379;
con.dbindex = 14;
redis_server.push_back(con);
}
{
/// DB1
redis::connection_data con;
con.host = host;
con.port = 6380;
con.dbindex = 14;
redis_server.push_back(con);
}
{
/// DB2
redis::connection_data con;
con.host = host;
con.port = 6381;
con.dbindex = 14;
redis_server.push_back(con);
}
{
/// DB3
redis::connection_data con;
con.host = host;
con.port = 6382;
con.dbindex = 14;
redis_server.push_back(con);
}
boost::shared_ptr<redis::client> cluster(
new redis::client(redis_server.begin(), redis_server.end() )
);
return cluster;
}