@keyvhq/redis
Advanced tools
Comparing version
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/microlinkhq/keyv", | ||
"version": "1.6.10", | ||
"version": "1.6.13", | ||
"main": "src/index.js", | ||
@@ -63,3 +63,3 @@ "author": { | ||
"types": "./src/index.d.ts", | ||
"gitHead": "c532b783b04d15edbaedb1f995745eae7f14d3a2" | ||
"gitHead": "9c1cf840af01eb0282d65d4b529e18c5f929660c" | ||
} |
@@ -52,5 +52,5 @@ # @keyvhq/redis [<img width="100" align="right" src="https://keyv.js.org/media/logo-sunset.svg" alt="keyv">](https://github.com/microlinkhq/keyv) | ||
**@keyvhq/redis** © [Luke Childs](https://lukechilds.co), Released under the [MIT](https://github.com/microlinkhq/keyv/blob/master/LICENSE.md) License.<br/> | ||
**@keyvhq/redis** © [Luke Childs](https://lukechilds.co), released under the [MIT](https://github.com/microlinkhq/keyv/blob/master/LICENSE.md) License.<br/> | ||
Maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/keyv/contributors). | ||
> [microlink.io](https://microlink.io) · GitHub [@MicrolinkHQ](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq) | ||
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq) |
@@ -7,2 +7,11 @@ 'use strict' | ||
const normalizeOptions = (...args) => Object.assign({ emitErrors: true }, ...args) | ||
const normalizeArguments = (input, options) => { | ||
if (input instanceof Redis) return [input, normalizeOptions(options)] | ||
const { uri, ...opts } = Object.assign(typeof input === 'string' ? { uri: input } : input, options) | ||
const normalizedOpts = normalizeOptions(opts) | ||
return [new Redis(uri, normalizedOpts), normalizedOpts] | ||
} | ||
class KeyvRedis extends EventEmitter { | ||
@@ -12,17 +21,10 @@ constructor (uri, options) { | ||
if (uri instanceof Redis) { | ||
this.redis = uri | ||
} else { | ||
options = Object.assign( | ||
{ | ||
emitErrors: true | ||
}, | ||
typeof uri === 'string' ? { uri } : uri, | ||
options | ||
) | ||
this.redis = new Redis(options.uri, options) | ||
} | ||
const [redis, { emitErrors }] = normalizeArguments(uri, options) | ||
if (options && options.emitErrors !== false) { | ||
this.redis.on('error', error => this.emit('error', error)) | ||
this.redis = redis | ||
if (emitErrors) { | ||
this.redis.on('error', error => { | ||
this.emit('error', error) | ||
}) | ||
} | ||
@@ -29,0 +31,0 @@ } |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
7596
2.98%0
-100%93
-1.06%