From 44350ce9e611f8a8d9199b6e13ca49e41fba1f3f Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 19:59:41 -0500 Subject: [PATCH] Clean up redis store --- TODO | 1 - lib/redis_document_store.js | 32 ++++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 73e4759..1636d2c 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ cache headers for static assets -make redis connection into a separate method tests diff --git a/lib/redis_document_store.js b/lib/redis_document_store.js index ac09b28..2ba56dc 100644 --- a/lib/redis_document_store.js +++ b/lib/redis_document_store.js @@ -2,25 +2,29 @@ var redis = require('redis'); var winston = require('winston'); var hashlib = require('hashlib'); -// TODO move to a different method (conn) var RedisDocumentStore = function(options) { if (!RedisDocumentStore.client) { - var host = options.host || '127.0.0.1'; - var port = options.port || 6379; - var index = options.db || 0; - RedisDocumentStore.client = redis.createClient(port, host); - RedisDocumentStore.client.select(index, function(err, reply) { - if (err) { - winston.error('error connecting to redis index ' + index, { error: error.message }); - process.exit(1); - } - else { - winston.info('connected to redis on ' + host + ':' + port + '/' + index); - } - }); + RedisDocumentStore.connect(options); } }; +// Create a connection according to config +RedisDocumentStore.connect = function(options) { + var host = options.host || '127.0.0.1'; + var port = options.port || 6379; + var index = options.db || 0; + RedisDocumentStore.client = redis.createClient(port, host); + RedisDocumentStore.client.select(index, function(err, reply) { + if (err) { + winston.error('error connecting to redis index ' + index, { error: error.message }); + process.exit(1); + } + else { + winston.info('connected to redis on ' + host + ':' + port + '/' + index); + } + }); +}; + // Save file in a key RedisDocumentStore.prototype.set = function(key, data, callback) { RedisDocumentStore.client.set(key, data, function(err, reply) {