Package Exports
- machinepack-redis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (machinepack-redis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
machinepack-redis
Docs Browse other machines FAQ Newsgroup
Structured Node.js bindings for Redis.
Installation

$ npm install machinepack-redis --save --save-exactUsage
For the latest usage documentation, version information, and test status of this module, see http://node-machine.org/machinepack-redis. The generated manpages for each machine contain a complete reference of all expected inputs, possible exit states, and example return values. If you need more help, or find a bug, jump into Gitter or leave a message in the project newsgroup.
Quick Start
To run this example
First, if your Redis server is not running yet, open a new terminal window and do:
redis-serverNext, copy the example code below to a new
.jsfile somewhere in your project (e.g.examples/basic-usage.js). Then run:npm install machinepack-redis --save --save-exactFinally, run the example:
node examples/basic-usage.js
/**
* Module dependencies
*/
var Redis = require('machinepack-redis');
Redis.createManager({
connectionString: 'redis://127.0.0.1:6379',
onUnexpectedFailure: function (err){ console.warn('WARNING: unexpected failure. Details:',err); }
}).exec(function (err, report) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
var mgr = report.manager;
Pack.getConnection({
manager: mgr
}).exec(function (err, report) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
console.log('CONNECTED!');
// Now you can use the redis client however you like!
//
// To use the connection:
// `report.connection`
var redisClient = report.connection;
//
// See http://www.sitepoint.com/using-redis-node-js/ for more, but as a quick example:
redisClient.set('stuff', 'things', function(err, reply) {
// If "SET" failed...
if (err) {
// Handle failed "SET"
// ...
console.error('SET failed:',err);
// Always release the connection when finished:
Redis.releaseConnection({ connection: redisClient }).exec({
error: function (err){ console.error('UNEXPECTED ERROR:',err); },
success: function (report){ console.log('Connection released.'); }
});
return;
}
// Otherwise "SET" was successful.
// Do stuff
console.log('mmk set that.');
// ....
// Release the connection when finished:
// (note that you can skip this step and just destroy the manager if you wish)
Redis.releaseConnection({ connection: redisClient }).exec(function(err) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
console.log('Connection released.');
// But ALWAYS destroy the connection manager when finished
Redis.destroyManager({ manager: mgr }).exec(function(err) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
console.log('Done. (Manager destroyed)');
});//</Redis.destroyManager>
});//</Redis.releaseConnection>
});//</client.set>
});//</Redis.getConnection>
});//</Redis.createManager>About 
This is a machinepack, an NPM module which exposes a set of related Node.js machines according to the machinepack specification. Documentation pages for the machines contained in this module (as well as all other NPM-hosted machines for Node.js) are automatically generated and kept up-to-date on the public registry. Learn more at http://node-machine.org/implementing/FAQ.
License
MIT © 2015 contributors