Skip to content

Instantly share code, notes, and snippets.

@clark0x
Last active August 29, 2015 14:01
Show Gist options
  • Save clark0x/384b39bbdd8f6ab7d874 to your computer and use it in GitHub Desktop.
Save clark0x/384b39bbdd8f6ab7d874 to your computer and use it in GitHub Desktop.
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