-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathredis.js
62 lines (54 loc) · 1.33 KB
/
redis.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
// https://github.com/mranney/node_redis
var properties = require("./properties");
var redisEnabled = false;
var redis;
var client;
function Redis() {
redisEnabled = properties.redis.enabled;
if (redisEnabled) {
redis = require("redis");
}
}
Redis.prototype.storeMessage = function (chatMessage) {
if (redisEnabled) {
initClient();
client.lpush("messages", chatMessage);
client.quit();
}
};
Redis.prototype.obtainMessages = function(start,amount,callback) {
if (redisEnabled) {
initClient();
client.lrange("messages", start, amount-1, function(err, replies) {
callback(replies);
});
client.quit();
} else {
callback([]);
}
};
Redis.prototype.writeWarning = function(message) {
if (redisEnabled) {
initClient();
client.lpush("warnings", message);
client.quit();
}
};
Redis.prototype.obtainWarnings = function(callback) {
if (redisEnabled) {
initClient();
client.lrange("warnings", 0, -1, function(err, replies){
callback(replies);
});
client.quit();
} else {
callback([]);
}
};
function initClient() {
client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
}
module.exports = Redis;