-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase.js
executable file
·45 lines (38 loc) · 1.25 KB
/
base.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
module.exports = function(fake){
var client;
if (fake){
client = fake;
} else {
var rtg = require("url").parse(process.env.REDISTOGO_URL);
console.log(rtg.port, rtg.hostname);
client = require("redis").createClient(rtg.port, rtg.hostname);
client.auth(rtg.auth.split(":")[1]);
}
// } else {
// client = require("redis").createClient();
// }
var base = {};
base.addQuack = function(id, quack, hashtag, time, userID, lat, lon, address, callback){
client.hmset(id, "quack", quack, "hashtag", hashtag, "time", time, "userID", userID, "id", id, "lat", lat, "lon", lon, "address", address, callback);
};
base.getQuax = function(quackStore, onEnd){
client.keys('*', function(err, keys){
keys.sort().forEach(function(e){
client.hgetall(e, function(err, quack){
if (!err){
quackStore.push(quack);
if (quackStore.length === keys.length) onEnd();
}
});
});
});
};
base.quackle = function(id){
client.del(id, function(err, reply){
if (!err){
console.log(reply + " quack removed from Db");
}
});
};
return base;
};