machinepack-redis
Advanced tools
Comparing version 1.0.3 to 1.1.1
@@ -68,7 +68,6 @@ module.exports = { | ||
fn: function (inputs, exits){ | ||
var isFunction = require('lodash.isfunction'); | ||
var isObject = require('lodash.isobject'); | ||
var _ = require('@sailshq/lodash'); | ||
// Ducktype provided "connection" (which is actually a redis client) | ||
if (!isObject(inputs.connection) || !isFunction(inputs.connection.end) || !isFunction(inputs.connection.removeAllListeners)) { | ||
if (!_.isObject(inputs.connection) || !_.isFunction(inputs.connection.end) || !_.isFunction(inputs.connection.removeAllListeners)) { | ||
return exits.badConnection(); | ||
@@ -75,0 +74,0 @@ } |
@@ -76,7 +76,6 @@ module.exports = { | ||
fn: function (inputs, exits){ | ||
var isFunction = require('lodash.isfunction'); | ||
var isObject = require('lodash.isobject'); | ||
var _ = require('@sailshq/lodash'); | ||
// Ducktype provided "connection" (which is actually a redis client) | ||
if (!isObject(inputs.connection) || !isFunction(inputs.connection.end) || !isFunction(inputs.connection.removeAllListeners)) { | ||
if (!_.isObject(inputs.connection) || !_.isFunction(inputs.connection.end) || !_.isFunction(inputs.connection.removeAllListeners)) { | ||
return exits.badConnection(); | ||
@@ -99,10 +98,2 @@ } | ||
// Set up the redis set callback that will be used by both set or setex | ||
var redisSetCallback = function (err){ | ||
if (err) { | ||
return exits.error(err); | ||
} | ||
return exits.success(); | ||
}; | ||
// If a TTL is set and its greater than zero, use SETEX as it is atomic | ||
@@ -113,7 +104,14 @@ // and is the equivalent of: | ||
// http://redis.io/commands/setex | ||
if (inputs.ttl > 0) { | ||
redisClient.setex(inputs.key, inputs.ttl, inputs.value, redisSetCallback); | ||
} else { | ||
redisClient.set(inputs.key, inputs.value, redisSetCallback); | ||
} | ||
(function (proceed){ | ||
if (inputs.ttl > 0) { | ||
redisClient.setex(inputs.key, inputs.ttl, inputs.value, proceed); | ||
} else { | ||
redisClient.set(inputs.key, inputs.value, proceed); | ||
} | ||
})(function afterSetOrSetEx(err){ | ||
if (err) { | ||
return exits.error(err); | ||
} | ||
return exits.success(); | ||
});//</self-calling function> | ||
@@ -120,0 +118,0 @@ } |
@@ -27,3 +27,3 @@ module.exports = { | ||
description: 'A string containing all metadata and credentials necessary for connecting to the Redis database.', | ||
example: 'redis://127.0.0.1:6379', | ||
example: 'redis://:secret@127.0.0.1:6379/12', | ||
required: true | ||
@@ -116,4 +116,3 @@ }, | ||
var Url = require('url'); | ||
var isObject = require('lodash.isobject'); | ||
var isFunction = require('lodash.isfunction'); | ||
var _ = require('@sailshq/lodash'); | ||
@@ -123,3 +122,3 @@ // Ensure that, if provided, `meta` is a dictionary. | ||
if (inputs.meta !== undefined) { | ||
if (!isObject(inputs.meta) || isFunction(inputs.meta)) { | ||
if (!_.isObject(inputs.meta) || _.isFunction(inputs.meta)) { | ||
return exits.error('If provided, `meta` must be a dictionary.'); | ||
@@ -126,0 +125,0 @@ } |
@@ -80,7 +80,6 @@ module.exports = { | ||
fn: function (inputs, exits){ | ||
var isFunction = require('lodash.isfunction'); | ||
var isObject = require('lodash.isobject'); | ||
var _ = require('@sailshq/lodash'); | ||
// Ducktype provided "connection" (which is actually a redis client) | ||
if (!isObject(inputs.connection) || !isFunction(inputs.connection.end) || !isFunction(inputs.connection.removeAllListeners)) { | ||
if (!_.isObject(inputs.connection) || !_.isFunction(inputs.connection.end) || !_.isFunction(inputs.connection.removeAllListeners)) { | ||
return exits.badConnection(); | ||
@@ -87,0 +86,0 @@ } |
@@ -68,7 +68,6 @@ module.exports = { | ||
fn: function (inputs, exits){ | ||
var isFunction = require('lodash.isfunction'); | ||
var isObject = require('lodash.isobject'); | ||
var _ = require('@sailshq/lodash'); | ||
// Ducktype provided "connection" (which is actually a redis client) | ||
if (!isObject(inputs.connection) || !isFunction(inputs.connection.end) || !isFunction(inputs.connection.removeAllListeners)) { | ||
if (!_.isObject(inputs.connection) || !_.isFunction(inputs.connection.end) || !_.isFunction(inputs.connection.removeAllListeners)) { | ||
return exits.badConnection(); | ||
@@ -75,0 +74,0 @@ } |
@@ -24,2 +24,9 @@ module.exports = { | ||
}, | ||
timeout: { | ||
friendlyName: 'Timeout', | ||
description: 'The amount of time, in milliseconds, to allow for a successful connection to take place.', | ||
example: 10000, | ||
defaultsTo: 15000 | ||
}, | ||
// | ||
@@ -81,4 +88,5 @@ meta: { | ||
fn: function (inputs, exits){ | ||
var isFunction = require('lodash.isfunction'); | ||
var _ = require('@sailshq/lodash'); | ||
var redis = require('redis'); | ||
var flaverr = require('flaverr'); | ||
@@ -93,2 +101,5 @@ // Build a local variable (`redisClientOptions`) to house a dictionary | ||
// Declare a var to hold the Redis connection timeout identifier, so it can be cleared later. | ||
var redisConnectionTimeout; | ||
// Create Redis client | ||
@@ -122,2 +133,3 @@ var client; | ||
function onPreConnectionEnd (){ | ||
clearTimeout(redisConnectionTimeout); | ||
client.removeListener('end', onPreConnectionEnd); | ||
@@ -133,2 +145,8 @@ client.removeListener('error', onPreConnectionError); | ||
} | ||
// Add a timeout for the initial Redis session connection. | ||
redisConnectionTimeout = setTimeout(function() { | ||
return exits.error(flaverr('E_REDIS_CONNECTION_TIMED_OUT', new Error('Took too long to connect to the specified Redis session server.\nYou can change the allowed connection time by setting the `timeout` input (currently ' + inputs.timeout + 'ms).'))); | ||
}, inputs.timeout); | ||
//////////////////////////////////////////////////////////////////////// | ||
@@ -146,2 +164,3 @@ | ||
client.once('ready', function onConnectionReady (){ | ||
clearTimeout(redisConnectionTimeout); | ||
client.removeListener('end', onPreConnectionEnd); | ||
@@ -157,22 +176,42 @@ client.removeListener('error', onPreConnectionError); | ||
// we'll just handle this error event silently (to prevent crashing). | ||
if (!isFunction(inputs.manager.onUnexpectedFailure)) { | ||
if (!_.isFunction(inputs.manager.onUnexpectedFailure)) { | ||
return; | ||
} | ||
var errToSend = new Error; | ||
errToSend.connection = client; | ||
errToSend.failureType = 'error'; | ||
if (err) { | ||
errToSend.originalError = err; | ||
if (/ECONNREFUSED/g.test(err)) { | ||
inputs.manager.onUnexpectedFailure(new Error( | ||
'Error emitted from Redis client: Connection to Redis server was lost (ECONNREFUSED). ' + | ||
'Waiting for Redis client to come back online (if configured to do so, auto-reconnecting behavior ' + | ||
'is happening in the background). Currently there are ' + client.connections + ' underlying Redis connections.\n' + | ||
'Error details:' + err.stack | ||
)); | ||
errToSend.message = | ||
'Error emitted from Redis client: Connection to Redis server was lost (ECONNREFUSED). ' + | ||
'Waiting for Redis client to come back online (if configured to do so, auto-reconnecting behavior ' + | ||
'is happening in the background). Currently there are ' + client.connections + ' underlying Redis connections.\n' + | ||
'Error details:' + err.stack; | ||
} else { | ||
inputs.manager.onUnexpectedFailure(new Error('Error emitted from Redis client.\nError details:' + err.stack)); | ||
errToSend.message = 'Error emitted from Redis client.\nError details:' + err.stack; | ||
} | ||
} else { | ||
inputs.manager.onUnexpectedFailure(new Error('Error emitted from Redis client.\n (no other information available)')); | ||
errToSend.message = 'Error emitted from Redis client.\n (no other information available)'; | ||
} | ||
inputs.manager.onUnexpectedFailure(errToSend); | ||
}); | ||
client.on('end', function onIntraConnectionEnd () { | ||
// If manager was not provisioned with an `onUnexpectedFailure`, | ||
// we'll just handle this error event silently (to prevent crashing). | ||
if (!_.isFunction(inputs.manager.onUnexpectedFailure)) { | ||
return; | ||
} | ||
var errToSend = new Error('Redis client disconnected.'); | ||
errToSend.connection = client; | ||
errToSend.failureType = 'end'; | ||
inputs.manager.onUnexpectedFailure(errToSend); | ||
}); | ||
// Now track this Redis client as one of the "redisClients" on our manager | ||
@@ -179,0 +218,0 @@ // (since we want to be able to call destroyManager to wipe them all) |
@@ -56,7 +56,6 @@ module.exports = { | ||
fn: function (inputs, exits) { | ||
var isFunction = require('lodash.isfunction'); | ||
var isObject = require('lodash.isobject'); | ||
var _ = require('@sailshq/lodash'); | ||
// Validate provided connection (which is actually a redis client) | ||
if ( !isObject(inputs.connection) || !isFunction(inputs.connection.end) || !isFunction(inputs.connection.removeAllListeners) ) { | ||
if ( !_.isObject(inputs.connection) || !_.isFunction(inputs.connection.end) || !_.isFunction(inputs.connection.removeAllListeners) ) { | ||
return exits.badConnection(); | ||
@@ -63,0 +62,0 @@ } |
{ | ||
"name": "machinepack-redis", | ||
"version": "1.0.3", | ||
"version": "1.1.1", | ||
"description": "Structured Node.js bindings for Redis.", | ||
@@ -27,7 +27,7 @@ "scripts": { | ||
"dependencies": { | ||
"@sailshq/lodash": "^3.10.2", | ||
"async": "2.0.1", | ||
"lodash.isfunction": "3.0.8", | ||
"lodash.isobject": "3.0.2", | ||
"flaverr": "^1.1.1", | ||
"machine": "^13.0.0-11", | ||
"redis": "2.4.2" | ||
"redis": "2.6.3" | ||
}, | ||
@@ -47,2 +47,3 @@ "devDependencies": { | ||
"get-connection", | ||
"create-connection-url", | ||
"release-connection", | ||
@@ -49,0 +50,0 @@ "get-cached-value", |
@@ -9,3 +9,2 @@ /** | ||
/** | ||
@@ -28,6 +27,5 @@ * Note: These tests should ideally not be redis-specific. | ||
error: done, | ||
success: function (report){ | ||
success: function (result){ | ||
// Save reference to manager. | ||
var manager = report.manager; | ||
var manager = result.manager; | ||
Pack.getConnection({ | ||
@@ -46,3 +44,3 @@ manager: manager | ||
it('should fail to connect to an invalid port', function (done){ | ||
var manager = Pack.createManager({ | ||
Pack.createManager({ | ||
connectionString: 'redis://127.0.0.1:9999', | ||
@@ -57,9 +55,8 @@ meta: { | ||
error: done, | ||
success: function (report){ | ||
success: function (result){ | ||
Pack.getConnection({ | ||
manager: manager | ||
manager: result.manager | ||
}).exec({ | ||
error: done, | ||
failed: function (result){ | ||
failed: function (){ | ||
done(); | ||
@@ -66,0 +63,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
76813
23
1701
0
+ Added@sailshq/lodash@^3.10.2
+ Addedflaverr@^1.1.1
+ Addedflaverr@1.10.0(transitive)
+ Addedredis@2.6.3(transitive)
+ Addedredis-parser@2.6.0(transitive)
- Removedlodash.isfunction@3.0.8
- Removedlodash.isobject@3.0.2
- Removedlodash.isfunction@3.0.8(transitive)
- Removedlodash.isobject@3.0.2(transitive)
- Removedredis@2.4.2(transitive)
Updatedredis@2.6.3