Socket
Socket
Sign inDemoInstall

machinepack-redis

Package Overview
Dependencies
Maintainers
1
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.


Version published
Weekly downloads
23K
increased by18.03%
Maintainers
1
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.getConnection({
  connectionString: 'redis://127.0.0.1:6379',
}).exec({
  error: function (err){
    console.error('UNEXPECTED ERROR:',err);
  },
  malformed: function (report){
    console.error('MALFORMED CONNECTION STRING:',report.error);
  },
  failedToConnect: function (report) {
    console.error('FAILED TO CONNECT:',report.error);
  },
  success: function (report){

    console.log('CONNECTED!');

    // Now you can use the connection 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.');
      // ....
      
      // 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.'); }
      });
    });//</client.set
  }
});//</Redis.getConnection>

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