data_types.cpp
1.3 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
/**
* Test special data type templates for multi-element replies using Redox.
*/
#include <iostream>
#include "../src/redox.hpp"
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;
using redox::Redox;
using redox::Command;
int main(int argc, char* argv[]) {
redox::Redox rdx; // Initialize Redox (default host/port)
if(!rdx.start()) return 1; // Start the event loop
rdx.del("mylist");
rdx.command_blocking("LPUSH mylist 1 2 3 4 5 6 7 8 9 10");
rdx.command<vector<string>>("LRANGE mylist 0 4",
[](Command<vector<string>>& c){
if(!c.ok()) return;
cout << "Last 5 elements as a vector: ";
for (const string& s : c.reply()) cout << s << " ";
cout << endl;
}
);
rdx.command<unordered_set<string>>("LRANGE mylist 0 4",
[](Command<unordered_set<string>>& c){
if(!c.ok()) return;
cout << "Last 5 elements as a hash: ";
for (const string& s : c.reply()) cout << s << " ";
cout << endl;
}
);
rdx.command<set<string>>("LRANGE mylist 0 4",
[&rdx](Command<set<string>>& c) {
if(c.ok()) {
cout << "Last 5 elements as a set: ";
for (const string& s : c.reply()) cout << s << " ";
cout << endl;
}
rdx.stop_signal();
}
);
rdx.block(); // Shut down the event loop
return 0;
}