-
Notifications
You must be signed in to change notification settings - Fork 0
/
records.cpp
40 lines (34 loc) · 910 Bytes
/
records.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
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
#include "record.h"
#include "records.h"
#include "redis.h"
const char *records_key = "movepoint.ru:records";
std::string Records::content(const char *key)
{
if (key == NULL)
key = records_key;
//TODO: optimize&cleanup
auto redis = get_redis();
std::vector<std::string> rs;
redis.lrange(key, 0, -1, std::back_inserter(rs));
std::vector<Record> records;
for (const auto &r : rs) {
std::istringstream s(r);
Record rec;
s >> rec;
records.push_back(rec);
}
std::stringstream s;
std::copy(std::begin(records),
std::end(records),
std::ostream_iterator<Record>(s));
return s.str();
}
void Records::add(const std::string &meta, const std::string &url)
{
auto redis = get_redis();
redis.rpush(records_key, meta + "\n" + url);
}