Skip to content
Browse files

Made using redis optional

  • Loading branch information...
1 parent 99e089c commit 1b25ad81f0f056fb6f8fe643ddc0af6bd7a8f9fe @jettro committed Apr 24, 2011
Showing with 30 additions and 13 deletions.
  1. +5 −1 config/template-config.json
  2. +24 −10 redis.js
  3. +1 −2 socketio.js
View
6 config/template-config.json
@@ -3,5 +3,9 @@
"key":"YOUR KEY",
"secret":"YOUR SECRET"
},
- "host":"http://localhost:8008"
+ "host":"http://localhost:8008",
+ "redis" : {
+ "enabled":false
+ }
+
}
View
34 redis.js
@@ -1,21 +1,35 @@
// https://github.com/mranney/node_redis
-function Redis() {}
+var properties = require("./properties");
-var redis = require("redis");
+var redisEnabled = false;
+var redis;
var client;
+function Redis() {
+ redisEnabled = properties.redis.enabled;
+ if (redisEnabled) {
+ redis = require("redis");
+ }
+}
+
Redis.prototype.storeMessage = function (chatMessage) {
- initClient();
- client.lpush("messages",chatMessage);
- client.quit();
+ if (redisEnabled) {
+ initClient();
+ client.lpush("messages", chatMessage);
+ client.quit();
+ }
};
Redis.prototype.obtainMessages = function(callback) {
- initClient();
- client.lrange("messages",0,14,function(err, replies) {
- callback(replies);
- });
- client.quit();
+ if (redisEnabled) {
+ initClient();
+ client.lrange("messages", 0, 14, function(err, replies) {
+ callback(replies);
+ });
+ client.quit();
+ } else {
+ callback([]);
+ }
};
function initClient() {
View
3 socketio.js
@@ -21,8 +21,7 @@ var redis = new Redis();
redis.obtainMessages(function(replies) {
replies.forEach(function (reply, i) {
- var chat = JSON.parse(reply);
- buffer.push(chat);
+ buffer.push(JSON.parse(reply));
});
buffer.reverse();
});

0 comments on commit 1b25ad8

Please sign in to comment.
Something went wrong with that request. Please try again.