-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo5.cpp
More file actions
67 lines (63 loc) · 1.58 KB
/
demo5.cpp
File metadata and controls
67 lines (63 loc) · 1.58 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
#include <iostream>
#include "credis.h"
#include <algorithm>
#include <iterator>
#include <fstream>
using namespace std;
int main()
{
Redis redis;
redis.init("127.0.0.1",6379,"");
redis.connect();
for(char k='a';k<='z';++k)
{
vector<string> keys(50000);
vector<string> vals(50000);
for (int i =0; i<keys.size(); ++i)
{
keys[i] = redis.num2str<int>(i);
if(keys[i].size()<8)
{
string num = "00000000";
keys[i]=num.substr(keys[i].size()) + keys[i] + k ;
}
vals[i]= keys[i];
for(int j =0;j<vals[i].size();++j)
{
if(vals[i][j]<='9'&& vals[i][j]>='0')
vals[i][j]=vals[i][j]-'0'+'a';
}
random_shuffle(vals[i].begin(),vals[i].end());//打乱
}
//cout<<keys[987]<<" "<<vals[987]<<endl;
redis.mset(keys,vals);
}
vector<string> v;
redis.getKeys("string", "", 10000, v);
//redis.keys("*",v);
ofstream file_for_write;
file_for_write.open("./file/data.txt", ios::trunc);
file_for_write << "get all keys:"<<endl;
int ka=1;
for(int i=0;i<v.size();++i,++ka)
{
file_for_write << v[i] <<" ";
if(ka%10 ==0)
file_for_write<<endl;
}
file_for_write<<endl<<endl<<endl<<endl;
vector<string> vs;
redis.mget(v, vs);
file_for_write<<"get values:"<<endl;
int kt=1;
for(int i=0;i<vs.size();++i,++kt)
{
file_for_write << vs[i] << " ";
if(kt >= 10)
{
kt = 0x01;
file_for_write<<endl;
}
}
cout<<endl;
}