sailsjs user hook for redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api/hooks/redis/index.js | |
module.exports = function(sails) { | |
"use strict"; | |
/** | |
* Module dependencies. | |
*/ | |
var redis = require('then-redis'); | |
return { | |
defaults: { | |
globals: { | |
redis: true | |
}, | |
redis: { | |
host : 'localhost' | |
, port : 6379 | |
//, database : 1 | |
//, password : null | |
//, noDelay : true | |
//, timeout : 0 | |
//, returnBuffers: false | |
} | |
}, | |
initialize: function(done) { | |
var client = redis.createClient(sails.config.redis); | |
// Expose modules on `sails.hooks.redis` | |
this.client = client; | |
// Expose modules on `sails` | |
sails.redis = client; | |
// Expose globals (if enabled) | |
if (sails.config.globals && sails.config.globals.redis) { | |
global['redis'] = client; | |
} | |
done(); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment