@keyv/redis
Advanced tools
Comparing version 2.2.3 to 2.3.0
122
package.json
{ | ||
"name": "@keyv/redis", | ||
"version": "2.2.3", | ||
"description": "Redis storage adapter for Keyv", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "xo && nyc ava", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov", | ||
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov" | ||
}, | ||
"xo": { | ||
"extends": "xo-lukechilds", | ||
"rules": { | ||
"unicorn/prefer-module": 0 | ||
} | ||
}, | ||
"ava": { | ||
"require": [ | ||
"requirable" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jaredwray/keyv.git" | ||
}, | ||
"keywords": [ | ||
"redis", | ||
"keyv", | ||
"storage", | ||
"adapter", | ||
"key", | ||
"value", | ||
"store", | ||
"cache", | ||
"ttl" | ||
], | ||
"author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/jaredwray/keyv/issues" | ||
}, | ||
"homepage": "https://github.com/jaredwray/keyv", | ||
"dependencies": { | ||
"ioredis": "^4.28.5" | ||
}, | ||
"devDependencies": { | ||
"@keyv/test-suite": "*", | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"eslint-config-xo-lukechilds": "^1.0.1", | ||
"keyv": "*", | ||
"nyc": "^15.1.0", | ||
"requirable": "^1.0.5", | ||
"this": "^1.1.0", | ||
"xo": "^0.47.0" | ||
} | ||
"name": "@keyv/redis", | ||
"version": "2.3.0", | ||
"description": "Redis storage adapter for Keyv", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "xo && nyc ava", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov", | ||
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov" | ||
}, | ||
"xo": { | ||
"extends": "xo-lukechilds", | ||
"rules": { | ||
"unicorn/prefer-module": 0 | ||
} | ||
}, | ||
"ava": { | ||
"require": [ | ||
"requirable" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jaredwray/keyv.git" | ||
}, | ||
"keywords": [ | ||
"redis", | ||
"keyv", | ||
"storage", | ||
"adapter", | ||
"key", | ||
"value", | ||
"store", | ||
"cache", | ||
"ttl" | ||
], | ||
"author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/jaredwray/keyv/issues" | ||
}, | ||
"homepage": "https://github.com/jaredwray/keyv", | ||
"dependencies": { | ||
"ioredis": "^5.0.3" | ||
}, | ||
"devDependencies": { | ||
"@keyv/test-suite": "*", | ||
"ava": "^4.1.0", | ||
"delay": "^5.0.0", | ||
"eslint-config-xo-lukechilds": "^1.0.1", | ||
"keyv": "*", | ||
"nyc": "^15.1.0", | ||
"requirable": "^1.0.5", | ||
"this": "^1.1.0", | ||
"tsd": "^0.20.0", | ||
"typescript": "^4.6.3", | ||
"xo": "^0.48.0" | ||
}, | ||
"tsd" : { | ||
"directory" : "test" | ||
}, | ||
"types": "./src/index.d.ts", | ||
"engines": { | ||
"node": ">= 12" | ||
}, | ||
"files": [ | ||
"src" | ||
] | ||
} |
@@ -0,1 +1,2 @@ | ||
// @ts-ignore | ||
const EventEmitter = require('events'); | ||
@@ -8,2 +9,4 @@ const Redis = require('ioredis'); | ||
this.ttlSupport = true; | ||
this.opts = {}; | ||
this.opts.dialect = 'redis'; | ||
@@ -13,3 +16,3 @@ if (uri instanceof Redis || uri instanceof Redis.Cluster) { | ||
} else { | ||
options = Object.assign({}, typeof uri === 'string' ? { uri } : uri, options); | ||
options = { ...(typeof uri === 'string' ? { uri } : uri), ...options }; | ||
this.redis = new Redis(options.uri, options); | ||
@@ -36,2 +39,7 @@ } | ||
getMany(keys) { | ||
return this.redis.mget(keys) | ||
.then(rows => rows.every(row => row === null) ? [] : rows); | ||
} | ||
set(key, value, ttl) { | ||
@@ -59,9 +67,44 @@ if (typeof value === 'undefined') { | ||
deleteMany(key) { | ||
return this.delete(key); | ||
} | ||
clear() { | ||
return this.redis.smembers(this._getNamespace()) | ||
.then(keys => this.redis.del(keys.concat(this._getNamespace()))) | ||
.then(keys => this.redis.del([...keys, ...this._getNamespace()])) | ||
.then(() => undefined); | ||
} | ||
async * iterator(namespace) { | ||
const scan = this.redis.scan.bind(this.redis); | ||
const get = this.redis.mget.bind(this.redis); | ||
async function * iterate(curs, pattern) { | ||
const [cursor, keys] = await scan(curs, 'MATCH', pattern); | ||
if (keys.length === 0) { | ||
return; | ||
} | ||
const values = await get(keys); | ||
for (const i in keys) { | ||
if (Object.prototype.hasOwnProperty.call(keys, i)) { | ||
const key = keys[i]; | ||
const value = values[i]; | ||
yield [key, value]; | ||
} | ||
} | ||
if (cursor !== '0') { | ||
yield * iterate(cursor, pattern); | ||
} | ||
} | ||
yield * iterate(0, `${namespace ? namespace + ':' : ''}*`); | ||
} | ||
has(key) { | ||
return this.redis.exists(key) | ||
.then(value => value !== 0); | ||
} | ||
} | ||
module.exports = KeyvRedis; |
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
110
6153
11
4
+ Added@ioredis/commands@1.2.0(transitive)
+ Addeddenque@2.1.0(transitive)
+ Addedioredis@5.4.1(transitive)
- Removeddenque@1.5.1(transitive)
- Removedioredis@4.28.5(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedp-map@2.1.0(transitive)
- Removedredis-commands@1.7.0(transitive)
Updatedioredis@^5.0.3