redis-client-pool v2.2.5
Redis Client Pool
A config driven redis client factory that pools.
The use case here is to create a convience module to ensure that you're able to share redis clients without all the initialization glue.
Install
Documentation
For each option set defined in config.redis, this module will create the respective exportable getter that will either return a cached client, or create a new client and add it into the client cache.
Options can be set directly, or within config.redis.options. See redis for details.
Clients are lazily initialized when accessed by the respective key.
Events
Redis Client pool emits the client event whenever a new client is created. Use this as an interface for binding to events on individual clients.
Methods
createClient( URI , poolClient )
Useful for generating clients manually, such as for Pub/Sub applications.
URI {String}
Accepts either a key from config.redis, or a URI with connection info.
If database is present within the URI query string, this will automatically select the respective database.
poolClient {Boolean}
Optional. If enabled, this will find a cached client, or create a new client and add it into the client cache.
Do not pool Pub/Sub clients.
createFactory( URI , poolClient )
This is a thin wrapper around createClient used as a client generator. See above.
Example
// .
// ├── config
// │ ├── default.json
// │ └── test.json
// default.json
// "redis" : "redis://localhost:6379",
// "session" : "redis://localhost:6379?database=2",
// "kue" : "redis://username:password@localhost:6379?database=3"
// },
// "session" : {
// "ttl" : 2592000000,
// "secure" : false
// },
// "cookie" : {
// "secret" : "install me!"
// }
// }
var client = require('redis-client-pool').session,
session = require('express-session'),
config = require('config');
var RedisStore = require('connect-redis')(session);
var store = new RedisStore({
client: client,
ttl: config.session.ttl
});