Skip to content

Instantly share code, notes, and snippets.

@clarkorz
Last active Aug 29, 2015
Embed
What would you like to do?
sailsjs user hook for redis
// 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