npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-redis-promise

v0.2.1

Published

Helper methods for Redis and global connection handler

Downloads

2

Readme

node-redis-promise

Build Status Code Coverage NPM

Helper methods for Redis and global connection handler

Note: This module uses ES6 code and it's meant to be used with iojs in conjunction with the --es_staging flag.

Install

npm install node-redis-promise --save

Usage Example

First you need to create a global connection, for example in your index.js:

var redis = require('node-redis-promise');

redis.connect();

And then in foo.js:

var redis = require('node-redis-promise');

redis.set({foo: 'bar'}, {
      prefix: 'bar_',
      expire: 60 // TTL of 1 minute
    })
    .then(function(key) {
      console.log(key); // => bar_sjk21x

      return redis.get(key, true); // get key and JSON-decode the value
    })
    .then(function(bar) {
      console.log(bar); // => {foo: 'bar'}
    })
    .catch(function(err) {
      // always handle your errors!
    });

If you need to quit the global conneciton you can do so it two ways:

var redis = require('node-redis-promise');
redis.quit();

// OR
global.redisCloseConn();

API

redis.connect()

Create a connection to Redis. Refer to the Node Redis module documentation.

Returns a Promise:

  • Fulfilled: on succesfull connection
  • Rejected: when a connection error occours

Promise, fulfilled on a succesfull connection and reject on a connection error

redis.get(key [, json])

Get the value of a key in Redis.

Params:

  • key (String): key to lookup
  • json (Boolean, optional): if set to true, JSON-decode the result

Returns: Promise

redis.set(value [, options])

Set a value in Redis, with some advanced options.

Params:

  • value: value to store
  • options (Object, optional): see below avaliable options

Options:

  • key (String): key to use when storing the value, defaults to a generated id using shortid
  • prefix (String): prefixes keys with the specified value
  • json (Boolean): JSON-encode the value before storing it. By default automatically attempts to detect Objects by using typeof value === 'object'
  • expire (Number): if sets, it will be used to set the TTL option on the value (seconds).

redis.client

Native Redis client

redis.quit

Safely closes the Redis conneciton

Tests

npm test

Contributing

Yes please. There is a .jshintrc and .jscsrc in this repo.

Use your favorite editor JsHint and JSCS plugins to lint the code, please.

License

The Unlicense