-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.js
50 lines (35 loc) · 1.18 KB
/
database.js
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
var redis = require('redis');
var client = redis.createClient(process.env.REDIS_URL, {
no_ready_check: true
});
var db = {};
db.addPostRedis = function(date, username, post, storeNo, res) {
client.hmset(date, "Username", username, "post", post, "storeNo", storeNo, "date", date );
}
db.addDateToList = function(date, username, post, res) {
client.rpush(["Dates", date]);
};
db.delPost = function(date, username, post, res) {
client.del(date, function(err, reply) {
console.log(reply + " in delete function");
});
};
db.tenFromList = function(date, username, post, res) {
client.lrange('Dates', 0, -1, function(err, reply) {
var pusharr = [];
count = 0;
for (var i = reply.length - 1; i > reply.length - 11; i--) {
var frontarr = [];
//console.log(db.getPostByDate(reply[i]));
client.hgetall(reply[i], function(err, object) {
frontarr.push(object);
count++;
if (count === 10) {
// console.log(frontarr);
res.end(JSON.stringify(frontarr));
}
});
}
});
};
module.exports = db;