From 4efc5d47d91128740aaa3ad86240e2b12c7d85f7 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Thu, 27 Sep 2012 11:46:53 -0400 Subject: [PATCH] Allow redistogo --- lib/document_stores/redis.js | 6 ++++-- package.json | 1 + server.js | 13 +++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/document_stores/redis.js b/lib/document_stores/redis.js index 22f0e61..91a93d4 100644 --- a/lib/document_stores/redis.js +++ b/lib/document_stores/redis.js @@ -8,9 +8,11 @@ var winston = require('winston'); // options[db] - The db to use (default 0) // options[expire] - The time to live for each key set (default never) -var RedisDocumentStore = function(options) { +var RedisDocumentStore = function(options, client) { this.expire = options.expire; - if (!RedisDocumentStore.client) { + if (client) { + RedisDocumentStore.client = client; + } else if (!RedisDocumentStore.client) { RedisDocumentStore.connect(options); } }; diff --git a/package.json b/package.json index 0b1556a..f66f6dd 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "dependencies": { "winston": "0.6.2", "connect": "1.9.2", + "redis-url": "0.1.0", "uglify-js": "1.3.3" }, "devDependencies": { diff --git a/server.js b/server.js index e40fc2f..8556ba9 100644 --- a/server.js +++ b/server.js @@ -34,8 +34,17 @@ if (!config.storage) { if (!config.storage.type) { config.storage.type = 'file'; } -var Store = require('./lib/document_stores/' + config.storage.type); -var preferredStore = new Store(config.storage); + +var Store, preferredStore; +if (config.storage.type === 'redistogo') { + var redisClient = require('redis-url').connect(process.env.REDISTOGO_URL); + Store = require('./lib/document_stores/redis'); + preferredStore = new Store(config.storage, redisClient); +} +else { + Store = require('./lib/document_stores/' + config.storage.type); + preferredStore = new Store(config.storage); +} // Compress the static javascript assets if (config.recompressStaticAssets) {