systemic-redis
Advanced tools
Comparing version 1.0.2 to 2.0.0
83
index.js
@@ -1,42 +0,61 @@ | ||
var async = require('async') | ||
var get = require('lodash.get') | ||
var format = require('util').format | ||
module.exports = (options) => { | ||
let redis = (options && options.redis) || require('redis'); | ||
let client; | ||
let config; | ||
let logger; | ||
module.exports = function(options) { | ||
const connectToRedis = () => | ||
new Promise((resolve) => { | ||
client.on('ready', () => { | ||
logger.info(`Connection to redis reached ready state.`); | ||
resolve(); | ||
}); | ||
}); | ||
var redis = options && options.redis || require('redis') | ||
var client | ||
var config | ||
var logger | ||
const closeRedisConnection = () => | ||
new Promise((resolve, reject) => { | ||
if (!client) { | ||
reject(new Error('Client has not been initialized.')); | ||
return; | ||
} | ||
function init(dependencies, cb) { | ||
config = dependencies.config | ||
logger = dependencies.logger || console | ||
cb() | ||
} | ||
logger.info(`Disconnecting from ${config.url || config.host || '127.0.0.1'}`); | ||
client.quit(() => { | ||
resolve(); | ||
}); | ||
}); | ||
function validate(cb) { | ||
if (!config) return cb(new Error('config is required')) | ||
cb() | ||
const start = async (dependencies) => { | ||
config = { ...dependencies.config }; | ||
if (!config) { | ||
throw new Error('config is required'); | ||
} | ||
function start(cb) { | ||
logger.info(format('Connecting to %s', config.url || config.host || '127.0.0.1')) | ||
client = redis.createClient(config) | ||
if (get(config, 'no_ready_check')) return cb(null, client) | ||
client.on('ready', function() { | ||
cb(null, client) | ||
}) | ||
({ logger } = dependencies); | ||
if (!logger) { | ||
logger = console; | ||
} | ||
function stop(cb) { | ||
if (!client) return cb() | ||
logger.info(format('Disconnecting from %s', config.url || config.host || '127.0.0.1')) | ||
client.quit(cb) | ||
logger.info(`Connecting to ${config.url || config.host || '127.0.0.1'}`); | ||
client = redis.createClient(config); | ||
if (config.no_ready_check) { | ||
connectToRedis(); | ||
} else { | ||
await connectToRedis(); | ||
} | ||
return { | ||
start: async.seq(init, validate, start), | ||
stop: stop | ||
} | ||
} | ||
return client; | ||
}; | ||
const stop = async () => { | ||
await closeRedisConnection(); | ||
}; | ||
return { | ||
start, | ||
stop, | ||
}; | ||
}; |
{ | ||
"name": "systemic-redis", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "A systemic redis component", | ||
"main": "index.js", | ||
"engineStrict": true, | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">=6.0.0" | ||
}, | ||
"scripts": { | ||
@@ -16,5 +21,3 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
"dependencies": { | ||
"async": "^2.0.0", | ||
"lodash.get": "^4.3.0", | ||
"redis": "^2.6.2" | ||
"redis": "^3.0.2" | ||
}, | ||
@@ -30,2 +33,2 @@ "devDependencies": {}, | ||
"homepage": "https://github.com/guidesmiths/systemic-redis#readme" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
2479
1
50
4
1
+ Addeddenque@1.5.1(transitive)
+ Addedredis@3.1.2(transitive)
+ Addedredis-errors@1.2.0(transitive)
+ Addedredis-parser@3.0.0(transitive)
- Removedasync@^2.0.0
- Removedlodash.get@^4.3.0
- Removedasync@2.6.4(transitive)
- Removeddouble-ended-queue@2.1.0-0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedredis@2.8.0(transitive)
- Removedredis-parser@2.6.0(transitive)
Updatedredis@^3.0.2