@keyv/redis 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +67 -55
- package/src/index.d.ts +24 -0
- package/src/index.js +45 -2
- package/.nyc_output/c17c3934-1699-442d-8326-3e558a85ef96.json +0 -1
- package/.nyc_output/e01c4be3-7f2c-40c1-b506-7a632572f30b.json +0 -1
- package/.nyc_output/processinfo/c17c3934-1699-442d-8326-3e558a85ef96.json +0 -1
- package/.nyc_output/processinfo/e01c4be3-7f2c-40c1-b506-7a632572f30b.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/test.js +0 -36
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Redis storage adapter for Keyv
|
|
4
4
|
|
|
5
|
-
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
|
|
6
|
+
[](https://codecov.io/gh/jaredwray/keyv)
|
|
7
7
|
[](https://www.npmjs.com/package/@keyv/redis)
|
|
8
8
|
|
|
9
9
|
Redis storage adapter for [Keyv](https://github.com/jaredwray/keyv).
|
package/package.json
CHANGED
|
@@ -1,57 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
2
|
+
"name": "@keyv/redis",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Redis storage adapter for Keyv",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "xo && nyc ava",
|
|
8
|
+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
|
|
9
|
+
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov"
|
|
10
|
+
},
|
|
11
|
+
"xo": {
|
|
12
|
+
"extends": "xo-lukechilds",
|
|
13
|
+
"rules": {
|
|
14
|
+
"unicorn/prefer-module": 0
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"ava": {
|
|
18
|
+
"require": [
|
|
19
|
+
"requirable"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/jaredwray/keyv.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"redis",
|
|
28
|
+
"keyv",
|
|
29
|
+
"storage",
|
|
30
|
+
"adapter",
|
|
31
|
+
"key",
|
|
32
|
+
"value",
|
|
33
|
+
"store",
|
|
34
|
+
"cache",
|
|
35
|
+
"ttl"
|
|
36
|
+
],
|
|
37
|
+
"author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/jaredwray/keyv/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/jaredwray/keyv",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"ioredis": "^5.0.3"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@keyv/test-suite": "*",
|
|
48
|
+
"ava": "^4.1.0",
|
|
49
|
+
"delay": "^5.0.0",
|
|
50
|
+
"eslint-config-xo-lukechilds": "^1.0.1",
|
|
51
|
+
"keyv": "*",
|
|
52
|
+
"nyc": "^15.1.0",
|
|
53
|
+
"requirable": "^1.0.5",
|
|
54
|
+
"this": "^1.1.0",
|
|
55
|
+
"tsd": "^0.20.0",
|
|
56
|
+
"typescript": "^4.6.3",
|
|
57
|
+
"xo": "^0.48.0"
|
|
58
|
+
},
|
|
59
|
+
"tsd" : {
|
|
60
|
+
"directory" : "test"
|
|
61
|
+
},
|
|
62
|
+
"types": "./src/index.d.ts",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">= 12"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"src"
|
|
68
|
+
]
|
|
57
69
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
|
|
3
|
+
declare class KeyvRedis extends EventEmitter {
|
|
4
|
+
readonly ttlSupport: false;
|
|
5
|
+
opts: Record<string, unknown>;
|
|
6
|
+
redis: any;
|
|
7
|
+
constructor(options?: string | KeyvRedis.Options);
|
|
8
|
+
_getNamespace(): string;
|
|
9
|
+
get(key: string): Promise<string | undefined>;
|
|
10
|
+
getMany(keys: string[]): Promise<string[] | undefined>;
|
|
11
|
+
set(key: string, value: string | undefined): Promise<any>;
|
|
12
|
+
delete(key: string): boolean;
|
|
13
|
+
deleteMany(keys: string[]): boolean;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
iterator(namespace: string | undefined): AsyncGenerator<any, void, any>;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
}
|
|
18
|
+
declare namespace KeyvRedis {
|
|
19
|
+
interface Options {
|
|
20
|
+
uri?: string | undefined;
|
|
21
|
+
dialect?: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export = KeyvRedis;
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
const EventEmitter = require('events');
|
|
2
3
|
const Redis = require('ioredis');
|
|
3
4
|
|
|
@@ -5,11 +6,13 @@ class KeyvRedis extends EventEmitter {
|
|
|
5
6
|
constructor(uri, options) {
|
|
6
7
|
super();
|
|
7
8
|
this.ttlSupport = true;
|
|
9
|
+
this.opts = {};
|
|
10
|
+
this.opts.dialect = 'redis';
|
|
8
11
|
|
|
9
12
|
if (uri instanceof Redis || uri instanceof Redis.Cluster) {
|
|
10
13
|
this.redis = uri;
|
|
11
14
|
} else {
|
|
12
|
-
options =
|
|
15
|
+
options = { ...(typeof uri === 'string' ? { uri } : uri), ...options };
|
|
13
16
|
this.redis = new Redis(options.uri, options);
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -31,6 +34,11 @@ class KeyvRedis extends EventEmitter {
|
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
getMany(keys) {
|
|
38
|
+
return this.redis.mget(keys)
|
|
39
|
+
.then(rows => rows.every(row => row === null) ? [] : rows);
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
set(key, value, ttl) {
|
|
35
43
|
if (typeof value === 'undefined') {
|
|
36
44
|
return Promise.resolve(undefined);
|
|
@@ -53,11 +61,46 @@ class KeyvRedis extends EventEmitter {
|
|
|
53
61
|
.then(() => items > 0));
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
deleteMany(key) {
|
|
65
|
+
return this.delete(key);
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
clear() {
|
|
57
69
|
return this.redis.smembers(this._getNamespace())
|
|
58
|
-
.then(keys => this.redis.del(keys
|
|
70
|
+
.then(keys => this.redis.del([...keys, ...this._getNamespace()]))
|
|
59
71
|
.then(() => undefined);
|
|
60
72
|
}
|
|
73
|
+
|
|
74
|
+
async * iterator(namespace) {
|
|
75
|
+
const scan = this.redis.scan.bind(this.redis);
|
|
76
|
+
const get = this.redis.mget.bind(this.redis);
|
|
77
|
+
async function * iterate(curs, pattern) {
|
|
78
|
+
const [cursor, keys] = await scan(curs, 'MATCH', pattern);
|
|
79
|
+
if (keys.length === 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const values = await get(keys);
|
|
84
|
+
for (const i in keys) {
|
|
85
|
+
if (Object.prototype.hasOwnProperty.call(keys, i)) {
|
|
86
|
+
const key = keys[i];
|
|
87
|
+
const value = values[i];
|
|
88
|
+
yield [key, value];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (cursor !== '0') {
|
|
93
|
+
yield * iterate(cursor, pattern);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
yield * iterate(0, `${namespace ? namespace + ':' : ''}*`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
has(key) {
|
|
101
|
+
return this.redis.exists(key)
|
|
102
|
+
.then(value => value !== 0);
|
|
103
|
+
}
|
|
61
104
|
}
|
|
62
105
|
|
|
63
106
|
module.exports = KeyvRedis;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/src/index.js":{"path":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/src/index.js","statementMap":{"0":{"start":{"line":1,"column":21},"end":{"line":1,"column":38}},"1":{"start":{"line":2,"column":14},"end":{"line":2,"column":32}},"2":{"start":{"line":6,"column":2},"end":{"line":6,"column":10}},"3":{"start":{"line":7,"column":2},"end":{"line":7,"column":25}},"4":{"start":{"line":9,"column":2},"end":{"line":14,"column":3}},"5":{"start":{"line":10,"column":3},"end":{"line":10,"column":20}},"6":{"start":{"line":12,"column":3},"end":{"line":12,"column":81}},"7":{"start":{"line":13,"column":3},"end":{"line":13,"column":48}},"8":{"start":{"line":16,"column":2},"end":{"line":16,"column":61}},"9":{"start":{"line":16,"column":34},"end":{"line":16,"column":59}},"10":{"start":{"line":20,"column":2},"end":{"line":20,"column":39}},"11":{"start":{"line":24,"column":2},"end":{"line":31,"column":6}},"12":{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},"13":{"start":{"line":27,"column":5},"end":{"line":27,"column":22}},"14":{"start":{"line":30,"column":4},"end":{"line":30,"column":17}},"15":{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},"16":{"start":{"line":36,"column":3},"end":{"line":36,"column":37}},"17":{"start":{"line":39,"column":2},"end":{"line":47,"column":59}},"18":{"start":{"line":41,"column":4},"end":{"line":43,"column":5}},"19":{"start":{"line":42,"column":5},"end":{"line":42,"column":50}},"20":{"start":{"line":45,"column":4},"end":{"line":45,"column":38}},"21":{"start":{"line":47,"column":15},"end":{"line":47,"column":57}},"22":{"start":{"line":51,"column":2},"end":{"line":53,"column":28}},"23":{"start":{"line":52,"column":18},"end":{"line":53,"column":26}},"24":{"start":{"line":53,"column":16},"end":{"line":53,"column":25}},"25":{"start":{"line":57,"column":2},"end":{"line":59,"column":26}},"26":{"start":{"line":58,"column":17},"end":{"line":58,"column":66}},"27":{"start":{"line":59,"column":15},"end":{"line":59,"column":24}},"28":{"start":{"line":63,"column":0},"end":{"line":63,"column":27}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":5,"column":1},"end":{"line":5,"column":2}},"loc":{"start":{"line":5,"column":27},"end":{"line":17,"column":2}},"line":5},"1":{"name":"(anonymous_1)","decl":{"start":{"line":16,"column":25},"end":{"line":16,"column":26}},"loc":{"start":{"line":16,"column":34},"end":{"line":16,"column":59}},"line":16},"2":{"name":"(anonymous_2)","decl":{"start":{"line":19,"column":1},"end":{"line":19,"column":2}},"loc":{"start":{"line":19,"column":17},"end":{"line":21,"column":2}},"line":19},"3":{"name":"(anonymous_3)","decl":{"start":{"line":23,"column":1},"end":{"line":23,"column":2}},"loc":{"start":{"line":23,"column":10},"end":{"line":32,"column":2}},"line":23},"4":{"name":"(anonymous_4)","decl":{"start":{"line":25,"column":9},"end":{"line":25,"column":10}},"loc":{"start":{"line":25,"column":18},"end":{"line":31,"column":4}},"line":25},"5":{"name":"(anonymous_5)","decl":{"start":{"line":34,"column":1},"end":{"line":34,"column":2}},"loc":{"start":{"line":34,"column":22},"end":{"line":48,"column":2}},"line":34},"6":{"name":"(anonymous_6)","decl":{"start":{"line":40,"column":9},"end":{"line":40,"column":10}},"loc":{"start":{"line":40,"column":15},"end":{"line":46,"column":4}},"line":40},"7":{"name":"(anonymous_7)","decl":{"start":{"line":47,"column":9},"end":{"line":47,"column":10}},"loc":{"start":{"line":47,"column":15},"end":{"line":47,"column":57}},"line":47},"8":{"name":"(anonymous_8)","decl":{"start":{"line":50,"column":1},"end":{"line":50,"column":2}},"loc":{"start":{"line":50,"column":13},"end":{"line":54,"column":2}},"line":50},"9":{"name":"(anonymous_9)","decl":{"start":{"line":52,"column":9},"end":{"line":52,"column":10}},"loc":{"start":{"line":52,"column":18},"end":{"line":53,"column":26}},"line":52},"10":{"name":"(anonymous_10)","decl":{"start":{"line":53,"column":10},"end":{"line":53,"column":11}},"loc":{"start":{"line":53,"column":16},"end":{"line":53,"column":25}},"line":53},"11":{"name":"(anonymous_11)","decl":{"start":{"line":56,"column":1},"end":{"line":56,"column":2}},"loc":{"start":{"line":56,"column":9},"end":{"line":60,"column":2}},"line":56},"12":{"name":"(anonymous_12)","decl":{"start":{"line":58,"column":9},"end":{"line":58,"column":10}},"loc":{"start":{"line":58,"column":17},"end":{"line":58,"column":66}},"line":58},"13":{"name":"(anonymous_13)","decl":{"start":{"line":59,"column":9},"end":{"line":59,"column":10}},"loc":{"start":{"line":59,"column":15},"end":{"line":59,"column":24}},"line":59}},"branchMap":{"0":{"loc":{"start":{"line":9,"column":2},"end":{"line":14,"column":3}},"type":"if","locations":[{"start":{"line":9,"column":2},"end":{"line":14,"column":3}},{"start":{"line":9,"column":2},"end":{"line":14,"column":3}}],"line":9},"1":{"loc":{"start":{"line":9,"column":6},"end":{"line":9,"column":58}},"type":"binary-expr","locations":[{"start":{"line":9,"column":6},"end":{"line":9,"column":26}},{"start":{"line":9,"column":30},"end":{"line":9,"column":58}}],"line":9},"2":{"loc":{"start":{"line":12,"column":31},"end":{"line":12,"column":70}},"type":"cond-expr","locations":[{"start":{"line":12,"column":57},"end":{"line":12,"column":64}},{"start":{"line":12,"column":67},"end":{"line":12,"column":70}}],"line":12},"3":{"loc":{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},"type":"if","locations":[{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},{"start":{"line":26,"column":4},"end":{"line":28,"column":5}}],"line":26},"4":{"loc":{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},"type":"if","locations":[{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},{"start":{"line":35,"column":2},"end":{"line":37,"column":3}}],"line":35},"5":{"loc":{"start":{"line":41,"column":4},"end":{"line":43,"column":5}},"type":"if","locations":[{"start":{"line":41,"column":4},"end":{"line":43,"column":5}},{"start":{"line":41,"column":4},"end":{"line":43,"column":5}}],"line":41}},"s":{"0":1,"1":1,"2":152,"3":152,"4":152,"5":2,"6":150,"7":150,"8":152,"9":7,"10":287,"11":29,"12":29,"13":11,"14":18,"15":29,"16":1,"17":28,"18":28,"19":1,"20":27,"21":28,"22":5,"23":5,"24":5,"25":127,"26":127,"27":127,"28":1},"f":{"0":152,"1":7,"2":287,"3":29,"4":29,"5":29,"6":28,"7":28,"8":5,"9":5,"10":5,"11":127,"12":127,"13":127},"b":{"0":[2,150],"1":[152,150],"2":[148,2],"3":[11,18],"4":[1,28],"5":[1,27]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"bd8f3b81707d244584617a53dd7adf94e42c4798","contentHash":"c5e135535b639a2ad3a20d9fad0afd67bb707402a023b20709855704d5b485fa"}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":12159,"argv":["/Users/jaredwray/.nvm/versions/node/v16.10.0/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/node_modules/.bin/ava"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis","time":1638740362141,"ppid":12158,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/.nyc_output/c17c3934-1699-442d-8326-3e558a85ef96.json","externalId":"","uuid":"c17c3934-1699-442d-8326-3e558a85ef96","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"c17c3934-1699-442d-8326-3e558a85ef96","pid":12163,"argv":["/Users/jaredwray/.nvm/versions/node/v16.10.0/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis","time":1638740362478,"ppid":12159,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/.nyc_output/e01c4be3-7f2c-40c1-b506-7a632572f30b.json","externalId":"","uuid":"e01c4be3-7f2c-40c1-b506-7a632572f30b","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/src/index.js"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"processes":{"c17c3934-1699-442d-8326-3e558a85ef96":{"parent":null,"children":["e01c4be3-7f2c-40c1-b506-7a632572f30b"]},"e01c4be3-7f2c-40c1-b506-7a632572f30b":{"parent":"c17c3934-1699-442d-8326-3e558a85ef96","children":[]}},"files":{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/redis/src/index.js":["e01c4be3-7f2c-40c1-b506-7a632572f30b"]},"externalIds":{}}
|
package/test/test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const test = require('ava');
|
|
2
|
-
const keyvTestSuite = require('@keyv/test-suite').default;
|
|
3
|
-
const { keyvOfficialTests } = require('@keyv/test-suite');
|
|
4
|
-
const Keyv = require('keyv');
|
|
5
|
-
const KeyvRedis = require('this');
|
|
6
|
-
const Redis = require('ioredis');
|
|
7
|
-
|
|
8
|
-
const REDIS_HOST = 'localhost';
|
|
9
|
-
const redisURI = `redis://${REDIS_HOST}`;
|
|
10
|
-
|
|
11
|
-
keyvOfficialTests(test, Keyv, redisURI, 'redis://foo');
|
|
12
|
-
|
|
13
|
-
const store = () => new KeyvRedis(redisURI);
|
|
14
|
-
|
|
15
|
-
keyvTestSuite(test, Keyv, store);
|
|
16
|
-
|
|
17
|
-
test('reuse a redis instance', async t => {
|
|
18
|
-
const redis = new Redis(redisURI);
|
|
19
|
-
redis.foo = 'bar';
|
|
20
|
-
const keyv = new KeyvRedis(redis);
|
|
21
|
-
t.is(keyv.redis.foo, 'bar');
|
|
22
|
-
|
|
23
|
-
await keyv.set('foo', 'bar');
|
|
24
|
-
const value = await redis.get('foo');
|
|
25
|
-
t.true(value === 'bar');
|
|
26
|
-
t.true(await keyv.get('foo') === value);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('set an undefined key', async t => {
|
|
30
|
-
const redis = new Redis(redisURI);
|
|
31
|
-
const keyv = new KeyvRedis(redis);
|
|
32
|
-
|
|
33
|
-
await keyv.set('foo2', undefined);
|
|
34
|
-
const result = await keyv.get('foo2');
|
|
35
|
-
t.true(result === undefined);
|
|
36
|
-
});
|