Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

machinepack-redis

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

machinepack-redis

Structured Node.js bindings for Redis.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-45.88%
Maintainers
2
Weekly downloads
 
Created
Source

node-machine logo machinepack-redis

Docs   Browse other machines   FAQ   Newsgroup

Structured Node.js bindings for Redis.

Installation   NPM version Build Status

$ 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
/**
 * 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   ![Gitter](https://badges.gitter.im/Join Chat.svg)

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

Keywords

FAQs

Package last updated on 08 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc