Skip to content
Snippets Groups Projects
Commit 0b956d13 authored by Andy Trevorah's avatar Andy Trevorah
Browse files

added support for client opts

parent 61b002bc
No related branches found
No related tags found
1 merge request!4added support for overriding redis config
Loading
Loading
@@ -51,6 +51,20 @@ Once you've got your `env` instance, here are some things you can do with it
 
`env.redis` will provide you with a singleton instance of a redis client or a new instance. It will use Redis Sentinel it it's configured.
 
Example configuration:
```json
{
"redisDb": 1,
"sentinel": {
"master-name": "test-master",
"hosts": ["localhost:46379"]
},
clientOpts: {
"return_buffers": true
}
}
```
* `env.redis.getClient()` - returns the main singleton Redis client.
* `env.redis.createClient([options])` - returns a new Redis client. Uses `redis` config by default.
* `env.redis.quitClient()` - closes a Redis client (don't do this with the main singleton client)
Loading
Loading
Loading
Loading
@@ -55,7 +55,7 @@ function createInstance(options, logger) {
var host = options.host;
var port = options.port;
 
client = redis.createClient(port, host);
client = redis.createClient(port, host, options.clientOpts);
}
switchDatabase(client, options.redisDb, logger);
 
Loading
Loading
@@ -66,8 +66,8 @@ function registerClient(client) {
clients.push(client);
}
 
function setupTransientClient(port, host, redisDb, logger) {
var client = redis.createClient(port, host);
function setupTransientClient(port, host, redisDb, clientOpts, logger) {
var client = redis.createClient(port, host, clientOpts);
 
switchDatabase(client, redisDb, logger);
 
Loading
Loading
@@ -89,13 +89,16 @@ function setupTransientClient(port, host, redisDb, logger) {
exports.createTransientClient = function(mainClient, options, logger, callback) {
var host, port;
 
var redisDb = options.redisDb;
var clientOpts = options.clientOpts;
if(options.sentinel) {
var master = mainClient.activeMasterClient;
 
/* No master yet? Wait... */
if(!master) {
mainClient.on('reconnected', function() {
var client = setupTransientClient(mainClient.activeMasterClient.port, mainClient.activeMasterClient.host, options.redisDb, logger);
var client = setupTransientClient(mainClient.activeMasterClient.port, mainClient.activeMasterClient.host, redisDb, clientOpts, logger);
callback(null, client);
});
 
Loading
Loading
@@ -109,7 +112,7 @@ exports.createTransientClient = function(mainClient, options, logger, callback)
port = options.port;
}
 
var client = setupTransientClient(port, host, options.redisDb, logger);
var client = setupTransientClient(port, host, redisDb, clientOpts, logger);
 
/* Callback in a second */
setImmediate(function() {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment