multiple-redis
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -24,10 +24,11 @@ <a name="MultiRedisClient"></a> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| params | <code>object</code> | The client init params | | ||
| [params.clients] | <code>Array</code> | <code>redis</code> | The redis client/s (if not provided, the connection info must be provided instead) | | ||
| [params.connectionInfo] | <code>Array</code> | <code>object</code> | The redis client/s connection info (if not provided, the redis clients must be provided) | | ||
| [params.connectionInfo.host] | <code>string</code> | The redis host | | ||
| [params.connectionInfo.port] | <code>number</code> | The redis port | | ||
| [params.options] | <code>Array</code> | Used when this client creates the redis clients (see redis module for more details) | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| params | <code>object</code> | | The client init params | | ||
| [params.clients] | <code>Array</code> | <code>redis</code> | | The redis client/s (if not provided, the connection info must be provided instead) | | ||
| [params.connectionInfo] | <code>Array</code> | <code>object</code> | | The redis client/s connection info (if not provided, the redis clients must be provided) | | ||
| [params.connectionInfo.host] | <code>string</code> | | The redis host | | ||
| [params.connectionInfo.port] | <code>number</code> | | The redis port | | ||
| [params.options] | <code>Array</code> | | Used when this client creates the redis clients (see redis module for more details) | | ||
| [params.options.mergeDuplicateEndpoints] | <code>boolean</code> | <code>true</code> | True to merge duplicate endpoint configurations and prevent needless redis client connections | | ||
@@ -99,8 +100,9 @@ <a name="MultiRedisClient.connected"></a> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| connectionInfo | <code>Array</code> | <code>object</code> | The redis client/s connection info | | ||
| connectionInfo.host | <code>string</code> | The redis host | | ||
| connectionInfo.port | <code>number</code> | The redis port | | ||
| [options] | <code>Array</code> | Used when this client creates the redis clients (see redis module for more details) | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| connectionInfo | <code>Array</code> | <code>object</code> | | The redis client/s connection info | | ||
| connectionInfo.host | <code>string</code> | | The redis host | | ||
| connectionInfo.port | <code>number</code> | | The redis port | | ||
| [options] | <code>Array</code> | | Used when this client creates the redis clients (see redis module for more details) | | ||
| [options.mergeDuplicateEndpoints] | <code>boolean</code> | <code>true</code> | True to merge duplicate endpoint configurations and prevent needless redis client connections | | ||
@@ -107,0 +109,0 @@ **Example** |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var redis = require('redis'); | ||
var async = require('async'); | ||
var asyncLib = require('async'); | ||
@@ -24,2 +24,3 @@ /** | ||
* @param {Array} [params.options] - Used when this client creates the redis clients (see redis module for more details) | ||
* @param {boolean} [params.options.mergeDuplicateEndpoints=true] - True to merge duplicate endpoint configurations and prevent needless redis client connections | ||
*/ | ||
@@ -40,6 +41,10 @@ function MultiRedisClient(params) { | ||
var options = params.options || {}; | ||
if (options.mergeDuplicateEndpoints === undefined) { | ||
options.mergeDuplicateEndpoints = true; | ||
} | ||
var connectionInfo = params.connectionInfo; | ||
if (!Array.isArray(connectionInfo)) { | ||
connectionInfo = [connectionInfo]; | ||
} else { | ||
} else if (options.mergeDuplicateEndpoints) { | ||
connectionInfo = self.getUniqueEndpoints(connectionInfo); | ||
@@ -236,5 +241,5 @@ } | ||
if (getCommand) { | ||
async.series(actions, onRedisFlowEnd); | ||
asyncLib.series(actions, onRedisFlowEnd); | ||
} else { | ||
async.parallel(actions, onRedisFlowEnd); | ||
asyncLib.parallel(actions, onRedisFlowEnd); | ||
} | ||
@@ -282,2 +287,3 @@ }; | ||
* @param {Array} [options] - Used when this client creates the redis clients (see redis module for more details) | ||
* @param {boolean} [options.mergeDuplicateEndpoints=true] - True to merge duplicate endpoint configurations and prevent needless redis client connections | ||
* @returns {MultiRedisClient} The multiple redis client instance | ||
@@ -284,0 +290,0 @@ * @example |
{ | ||
"name": "multiple-redis", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Run redis commands against multiple redis instances.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -127,2 +127,3 @@ # multiple-redis | ||
| ----------- | ------- | ----------- | | ||
| 2015-09-23 | v0.0.8 | Maintenance | | ||
| 2015-09-23 | v0.0.7 | Upgrade to redis 2.0 | | ||
@@ -129,0 +130,0 @@ | 2015-09-08 | v0.0.6 | Maintenance | |
@@ -18,7 +18,17 @@ 'use strict'; | ||
var emmitter = new EventEmitter(); | ||
var baseCreate = redis.createClient; | ||
function mockRedis() { | ||
return (process.env.MULTIPLE_REDIS_TEST_USE_REDIS !== 'true'); | ||
} | ||
redis.createClient = function (port, host, options) { | ||
var redisClient = { | ||
on: noop | ||
}; | ||
emmitter.emit('create', port, host, options, function (client) { | ||
var redisClient; | ||
if ((!mockRedis()) && (host === 'localhost') && (port === 6379) && options && (!options.mock)) { | ||
redisClient = baseCreate.call(redis, port, host, options); | ||
} else { | ||
redisClient = { | ||
on: noop | ||
}; | ||
} | ||
emmitter.emit('create', redisClient, port, host, options, function (client) { | ||
redisClient = client; | ||
@@ -98,2 +108,22 @@ }); | ||
it('connection info array with duplicates no merge', function () { | ||
var client = MultipleRedis.createClient([{ | ||
host: 'localhost1', | ||
port: 1234 | ||
}, { | ||
host: 'localhost2', | ||
port: 1234 | ||
}, { | ||
host: 'localhost2', | ||
port: 1234 | ||
}, { | ||
host: 'localhost1', | ||
port: 1234 | ||
}], { | ||
mergeDuplicateEndpoints: false | ||
}); | ||
assert.equal(client.clients.length, 4); | ||
}); | ||
it('single connection info', function () { | ||
@@ -110,6 +140,8 @@ var client = MultipleRedis.createClient({ | ||
var count = 0; | ||
var validateCreate = function (port, host, options) { | ||
/*jslint unparam: true*/ | ||
var validateCreate = function (redisClient, port, host, options) { | ||
if ((port === 1234) && (host.indexOf('options') === 0)) { | ||
assert.deepEqual(options, { | ||
someoption: 123 | ||
someoption: 123, | ||
mergeDuplicateEndpoints: true | ||
}); | ||
@@ -126,2 +158,3 @@ | ||
}; | ||
/*jslint unparam: false*/ | ||
@@ -143,6 +176,8 @@ emmitter.on('create', validateCreate); | ||
var count = 0; | ||
var validateCreate = function (port, host, options) { | ||
/*jslint unparam: true*/ | ||
var validateCreate = function (redisClient, port, host, options) { | ||
if ((port === 1234) && (host === 'singleOption')) { | ||
assert.deepEqual(options, { | ||
someoption: 'abc' | ||
someoption: 'abc', | ||
mergeDuplicateEndpoints: true | ||
}); | ||
@@ -159,2 +194,3 @@ | ||
}; | ||
/*jslint unparam: false*/ | ||
@@ -558,3 +594,66 @@ emmitter.on('create', validateCreate); | ||
}); | ||
describe('set and get tests', function () { | ||
it('valid', function (done) { | ||
this.timeout(10000); | ||
if (mockRedis()) { | ||
/*jslint unparam: true*/ | ||
var modifyClient = function (redisClient, port, host, options) { | ||
if ((host === 'localhost') && (port === 6379) && options && (!options.mock)) { | ||
redisClient.send_command = function (name, args, callback) { | ||
if (name === 'set') { | ||
redisClient[args[0]] = args[1]; | ||
callback(undefined, 'OK'); | ||
} else if (name === 'get') { | ||
callback(undefined, redisClient[args[0]]); | ||
} else { | ||
callback(new Error('Unsupported')); | ||
} | ||
}; | ||
} | ||
}; | ||
/*jslint unparam: false*/ | ||
emmitter.on('create', modifyClient); | ||
var orgDone = done; | ||
done = function () { | ||
emmitter.removeListener('create', modifyClient); | ||
orgDone(); | ||
}; | ||
} | ||
var client = MultipleRedis.createClient([{ | ||
host: 'localhost', | ||
port: 6379 | ||
}, { | ||
host: 'localhost', | ||
port: 6379 | ||
}], { | ||
mergeDuplicateEndpoints: false, | ||
mock: false | ||
}); | ||
client.set('my key', 'my value', function (error1, response1) { | ||
if (error1) { | ||
assert.fail(); | ||
} | ||
assert.isDefined(response1); | ||
setTimeout(function () { | ||
client.get('my key', function (error2, response2) { | ||
if (error2) { | ||
assert.fail(); | ||
} | ||
assert.equal(response2, 'my value'); | ||
done(); | ||
}); | ||
}, 50); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
74566
1225
136
2