machinepack-redis
Structured Node.js bindings for Redis.
Installation
$ npm install machinepack-redis --save --save-exact
Usage
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-server
Next, copy the example code below to a new .js
file somewhere in your project (e.g. examples/basic-usage.js
).
Then run:
npm install machinepack-redis --save --save-exact
Finally, run the example:
node examples/basic-usage.js
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!');
var redisClient = report.connection;
redisClient.set('stuff', 'things', function(err, reply) {
if (err) {
console.error('SET failed:',err);
Redis.releaseConnection({ connection: redisClient }).exec({
error: function (err){ console.error('UNEXPECTED ERROR:',err); },
success: function (report){ console.log('Connection released.'); }
});
return;
}
console.log('mmk set that.');
Redis.releaseConnection({ connection: redisClient }).exec(function(err) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
console.log('Connection released.');
Redis.destroyManager({ manager: mgr }).exec(function(err) {
if (err) { console.error('UNEXPECTED ERROR:',err); return; }
console.log('Done. (Manager destroyed)');
});
});
});
});
});
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