-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.js
More file actions
80 lines (64 loc) · 1.84 KB
/
DB.js
File metadata and controls
80 lines (64 loc) · 1.84 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
73
74
75
76
77
78
79
80
var redis = require('redis');
var client = redis.createClient(process.env.REDIS_URL, {
no_ready_check: true
});
var db = {};
var aCount = 0;
var qCount = 0;
db.addQHash = function(username, question, date){
console.log('im in the addQHash');
console.log(qCount);
qCount ++;
client.hmset(qCount, "username", username, "question", question, "date", date, "QID", qCount);
};
console.log(qCount);
db.addAHash = function(username, answer, date, qid){
aCount ++;
var aCountID = "A"+aCount;
client.hmset(aCountID, "username", username, "answer", answer, "date", date, "AID",aCountID, "QID", qid);
console.log ("addAHash QID " + qid);
console.log ("addAHash AID " + aCountID);
client.zadd('answer', qid, aCountID);
};
db.lastFiveAs = function(qid, callbackA){
//console.log('im in the getAnswers QID ' + qid);
client.ZREVRANGEBYSCORE ('answer', qid, qid, function(err, replyAs){
console.log('im in the getAnswers S.Set ' + replyAs);
console.log('im in the getAnswers QID ' + qid);
var i = replyAs.length;
client.multi()
.hgetall(qid)
.hgetall(replyAs[i])
.hgetall(replyAs[i-1])
.hgetall(replyAs[i-2])
.hgetall(replyAs[i-3])
.hgetall(replyAs[i-4])
.exec(function(err, repliesAs){
console.log("In the As multi" + repliesAs);
callbackA(repliesAs);
return(repliesAs);
})
});
}
var QDataArr = [];
db.lastTenQs = function(callback){
console.log('im in the lastTenQs');
var i = qCount;
console.log(qCount);
client.multi()
.hgetall(i)
.hgetall(i-1)
.hgetall(i-2)
.hgetall(i-3)
.hgetall(i-4)
.hgetall(i-5)
.hgetall(i-6)
.hgetall(i-7)
.hgetall(i-8)
.hgetall(i-9)
.exec(function(err, replies){
callback(replies);
return(replies);
});
};
module.exports = db;