redis-connector

ERROR: No README.md file found!

npm install redis-connector
48 downloads in the last month

redis-connector

for lazy people who don't want to spend more than one line connecting to their redis DB. Don't forget to depend on redis, too. We don't ship it because locking the version in redis-connector is silly.

connect(conf, cb)

There are two types of conf objects:

  • If it has a .get method, it will be called with 'redis:host', 'redis:port' and 'redis:pass' to get the respective values. This is most useful with nconf.
  • Otherwise, its .host, .port and .pass are read.

It authenticates if necessary and calls your callback with the db object. As a convenience, it also returns the db object.

If an error occurs, we won't catch it. It is assumed that the db is essential for your app to work and that starting without it is thus useless.

example

Connect to a db using a plain object for configuration and using the return value to get the db object.

var db = require('redis-connector')({
    'host': 'ray.redistogo.com',
    'port': 1234,
    'pass': 'banana'
}, dbConnected);

function dbConnected() {
    //do stuff with db!
}

You can also take the db in the callback

require('redis-connector')({
    'host': 'ray.redistogo.com',
    'port': 1234,
    'pass': 'banana'
}, doDbStuff);

function doDbStuff(db) {
    //do stuff with db!
}

And of course, you can do both.

npm loves you