1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-01 09:40:21 +01:00

Clean up redis store

This commit is contained in:
John Crepezzi 2011-11-18 19:59:41 -05:00
parent 00e2ca8d29
commit 44350ce9e6
2 changed files with 18 additions and 15 deletions

1
TODO
View file

@ -1,5 +1,4 @@
cache headers for static assets cache headers for static assets
make redis connection into a separate method
tests tests

View file

@ -2,25 +2,29 @@ var redis = require('redis');
var winston = require('winston'); var winston = require('winston');
var hashlib = require('hashlib'); var hashlib = require('hashlib');
// TODO move to a different method (conn)
var RedisDocumentStore = function(options) { var RedisDocumentStore = function(options) {
if (!RedisDocumentStore.client) { if (!RedisDocumentStore.client) {
var host = options.host || '127.0.0.1'; RedisDocumentStore.connect(options);
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);
}
});
} }
}; };
// 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 // Save file in a key
RedisDocumentStore.prototype.set = function(key, data, callback) { RedisDocumentStore.prototype.set = function(key, data, callback) {
RedisDocumentStore.client.set(key, data, function(err, reply) { RedisDocumentStore.client.set(key, data, function(err, reply) {