-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpersist.js
68 lines (62 loc) · 1.41 KB
/
persist.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var redis = require('redis')
, pollnameText = ''
, triggerWord = ''
, pollnameText = ''
, slackRes = ''
, client = ''
, rtg = ''
, operationComplete = false
, ts = Math.floor(Date.now() / 1000);
/*
* Set correct environment for redis.
*/
if (process.env.REDISTOGO_URL) {
rtg = require('url').parse(process.env.REDISTOGO_URL);
client = redis.createClient(rtg.port, rtg.hostname);
client.auth(rtg.auth.split(':')[1]);
} else {
client = redis.createClient();
}
/*
* TBD: there should be error handling on all of these to handle no reply responses.
*/
var dbActions = {
/*
* Set poll data.
*/
setPoll: function(pollKey, pollData, callback) {
client.set(pollKey, pollData, function (err, reply) {
if (reply) {
callback(reply);
}
});
},
/*
* Disable poll. The pollData var should have a field that sets the poll to inactive
*/
disablePoll: function(pollKey, pollData, callback) {
client.set(pollKey, pollData, function (err, reply) {
if (err) {
console.log(pollKey);
console.log(pollData);
console.log(err);
}
if (reply) {
callback(reply);
}
});
},
/*
* Get poll from id.
*/
getPoll: function(pollId, callback) {
client.get(pollId, function (err, reply) {
if (reply) {
callback(reply);
} else {
callback(null);
}
});
}
};
module.exports = dbActions;