Skip to content

Commit

Permalink
[api] Add support for Redis auth and optional callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Apr 5, 2011
1 parent 81e1883 commit 4094125
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/nconf/stores/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var Redis = exports.Redis = function (options) {
this.ttl = options.ttl || 60 * 60 * 1000;
this.cache = new Memory();
this.redis = redis.createClient(options.port, options.host);

if (options.auth) {
this.redis.auth(options.auth);
}
};

//
Expand All @@ -46,6 +50,9 @@ Redis.prototype.get = function (key, callback) {
mtime = this.cache.mtimes[key],
fullKey = nconf.key(this.namespace, key);

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

//
// If the key exists in the cache and the ttl is less than
// the value set for this instance, return from the cache.
Expand Down Expand Up @@ -117,6 +124,9 @@ Redis.prototype.set = function (key, value, callback) {
var self = this,
path = nconf.path(key);

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

function addKey (partial, next) {
var index = path.indexOf(partial),
base = [self.namespace].concat(path.slice(0, index)),
Expand Down Expand Up @@ -171,6 +181,9 @@ Redis.prototype.clear = function (key, callback) {
last = path.pop(),
fullKey = nconf.key(this.namespace, key);

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

//
// Clear the key from the cache for this instance
//
Expand Down Expand Up @@ -226,6 +239,9 @@ Redis.prototype.save = function (value, callback) {
var self = this,
keys = Object.keys(value);

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

//
// Clear all existing keys associated with this instance.
//
Expand All @@ -252,6 +268,9 @@ Redis.prototype.load = function (callback) {
var self = this,
result = {};

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

this.redis.smembers(nconf.key(this.namespace, 'keys'), function (err, keys) {
if (err) {
return callback(err);
Expand Down Expand Up @@ -282,6 +301,9 @@ Redis.prototype.load = function (callback) {
Redis.prototype.reset = function (callback) {
var self = this;

// Set the callback if not provided for "fire and forget"
callback = callback || function () { };

//
// Get the list of of top-level keys, then clear each of them
//
Expand Down

0 comments on commit 4094125

Please sign in to comment.