@keyv/redis 4.3.4 → 4.4.1
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 +10 -4
- package/dist/index.cjs +20 -13
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -9
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
Redis storage adapter for [Keyv](https://github.com/jaredwray/keyv).
|
|
11
11
|
|
|
12
12
|
# Features
|
|
13
|
-
* Built on top of [redis](https://npmjs.com/package/
|
|
13
|
+
* Built on top of [@redis/client](https://npmjs.com/package/@redis/client).
|
|
14
14
|
* TTL is handled directly by Redis.
|
|
15
15
|
* Supports Redis Clusters.
|
|
16
16
|
* Url connection string support or pass in your Redis Options
|
|
@@ -37,6 +37,12 @@ Redis storage adapter for [Keyv](https://github.com/jaredwray/keyv).
|
|
|
37
37
|
* [About Redis Sets and its Support in v4](#about-redis-sets-and-its-support-in-v4)
|
|
38
38
|
* [License](#license)
|
|
39
39
|
|
|
40
|
+
# Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install --save keyv @keyv/redis
|
|
44
|
+
```
|
|
45
|
+
|
|
40
46
|
# Usage
|
|
41
47
|
|
|
42
48
|
Here is a standard use case where we implement `Keyv` and `@keyv/redis`:
|
|
@@ -244,8 +250,8 @@ const keyv = new Keyv({ store: new KeyvRedis(tlsOptions) });
|
|
|
244
250
|
* **constructor([connection], [options])**
|
|
245
251
|
* **namespace** - The namespace to use for the keys.
|
|
246
252
|
* **client** - The Redis client instance.
|
|
247
|
-
* **keyPrefixSeparator** - The separator to use between the namespace and key.
|
|
248
|
-
* **clearBatchSize** - The number of keys to delete in a single batch.
|
|
253
|
+
* **keyPrefixSeparator** - The separator to use between the namespace and key. It can be set to a blank string.
|
|
254
|
+
* **clearBatchSize** - The number of keys to delete in a single batch. Has to be greater than 0. Default is `1000`.
|
|
249
255
|
* **useUnlink** - Use the `UNLINK` command for deleting keys isntead of `DEL`.
|
|
250
256
|
* **noNamespaceAffectsAll**: Whether to allow clearing all keys when no namespace is set (default is `false`).
|
|
251
257
|
* **set** - Set a key.
|
|
@@ -288,7 +294,7 @@ Here are some of the events you can listen to: https://www.npmjs.com/package/red
|
|
|
288
294
|
# Migrating from v3 to v4
|
|
289
295
|
|
|
290
296
|
Overall the API is the same as v3 with additional options and performance improvements. Here are the main changes:
|
|
291
|
-
* The `ioredis` library has been removed in favor of the `redis` aka `node-redis` library. If you want to use ioredis you can use `@keyv/
|
|
297
|
+
* The `ioredis` library has been removed in favor of the `redis` aka `node-redis` library. If you want to use ioredis you can use `@keyv/valkey`
|
|
292
298
|
* The `useUnlink` option has been added to use `UNLINK` instead of `DEL` and set to true by default.
|
|
293
299
|
* The `clearBatchSize` option has been added to set the number of keys to delete in a single batch.
|
|
294
300
|
* The `clear()` and `delete()` methods now use `UNLINK` instead of `DEL`. If you want to use `DEL` you can set the `useUnlink` option to `false`.
|
package/dist/index.cjs
CHANGED
|
@@ -31,20 +31,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Keyv: () => import_keyv2.Keyv,
|
|
34
|
-
createClient: () =>
|
|
35
|
-
createCluster: () =>
|
|
34
|
+
createClient: () => import_client2.createClient,
|
|
35
|
+
createCluster: () => import_client2.createCluster,
|
|
36
36
|
createKeyv: () => createKeyv,
|
|
37
37
|
default: () => KeyvRedis
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(index_exports);
|
|
40
40
|
var import_node_events = __toESM(require("events"), 1);
|
|
41
|
-
var
|
|
41
|
+
var import_client = require("@redis/client");
|
|
42
42
|
var import_keyv = require("keyv");
|
|
43
43
|
var import_cluster_key_slot = __toESM(require("cluster-key-slot"), 1);
|
|
44
|
-
var
|
|
44
|
+
var import_client2 = require("@redis/client");
|
|
45
45
|
var import_keyv2 = require("keyv");
|
|
46
46
|
var KeyvRedis = class extends import_node_events.default {
|
|
47
|
-
_client = (0,
|
|
47
|
+
_client = (0, import_client.createClient)();
|
|
48
48
|
_namespace;
|
|
49
49
|
_keyPrefixSeparator = "::";
|
|
50
50
|
_clearBatchSize = 1e3;
|
|
@@ -59,11 +59,11 @@ var KeyvRedis = class extends import_node_events.default {
|
|
|
59
59
|
super();
|
|
60
60
|
if (connect) {
|
|
61
61
|
if (typeof connect === "string") {
|
|
62
|
-
this._client = (0,
|
|
62
|
+
this._client = (0, import_client.createClient)({ url: connect });
|
|
63
63
|
} else if (connect.connect !== void 0) {
|
|
64
64
|
this._client = this.isClientCluster(connect) ? connect : connect;
|
|
65
65
|
} else if (connect instanceof Object) {
|
|
66
|
-
this._client = connect.rootNodes === void 0 ? (0,
|
|
66
|
+
this._client = connect.rootNodes === void 0 ? (0, import_client.createClient)(connect) : (0, import_client.createCluster)(connect);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
this.setOptions(options);
|
|
@@ -86,9 +86,12 @@ var KeyvRedis = class extends import_node_events.default {
|
|
|
86
86
|
* Get the options for the adapter.
|
|
87
87
|
*/
|
|
88
88
|
get opts() {
|
|
89
|
-
let url = "";
|
|
89
|
+
let url = "redis://localhost:6379";
|
|
90
90
|
if (this._client.options) {
|
|
91
|
-
|
|
91
|
+
const redisUrl = this._client.options?.url;
|
|
92
|
+
if (redisUrl) {
|
|
93
|
+
url = redisUrl;
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
const results = {
|
|
94
97
|
namespace: this._namespace,
|
|
@@ -143,7 +146,11 @@ var KeyvRedis = class extends import_node_events.default {
|
|
|
143
146
|
* Set the number of keys to delete in a single batch.
|
|
144
147
|
*/
|
|
145
148
|
set clearBatchSize(value) {
|
|
146
|
-
|
|
149
|
+
if (value > 0) {
|
|
150
|
+
this._clearBatchSize = value;
|
|
151
|
+
} else {
|
|
152
|
+
this.emit("error", "clearBatchSize must be greater than 0");
|
|
153
|
+
}
|
|
147
154
|
}
|
|
148
155
|
/**
|
|
149
156
|
* Get if Unlink is used instead of Del for clearing keys. This is more performant but may not be supported by all Redis versions.
|
|
@@ -501,10 +508,10 @@ var KeyvRedis = class extends import_node_events.default {
|
|
|
501
508
|
if (options.namespace) {
|
|
502
509
|
this._namespace = options.namespace;
|
|
503
510
|
}
|
|
504
|
-
if (options.keyPrefixSeparator) {
|
|
511
|
+
if (options.keyPrefixSeparator !== void 0) {
|
|
505
512
|
this._keyPrefixSeparator = options.keyPrefixSeparator;
|
|
506
513
|
}
|
|
507
|
-
if (options.clearBatchSize) {
|
|
514
|
+
if (options.clearBatchSize !== void 0 && options.clearBatchSize > 0) {
|
|
508
515
|
this._clearBatchSize = options.clearBatchSize;
|
|
509
516
|
}
|
|
510
517
|
if (options.useUnlink !== void 0) {
|
|
@@ -523,7 +530,7 @@ var KeyvRedis = class extends import_node_events.default {
|
|
|
523
530
|
function createKeyv(connect, options) {
|
|
524
531
|
connect ??= "redis://localhost:6379";
|
|
525
532
|
const adapter = new KeyvRedis(connect, options);
|
|
526
|
-
const keyv = new import_keyv.Keyv(
|
|
533
|
+
const keyv = new import_keyv.Keyv(adapter, { namespace: options?.namespace, useKeyPrefix: false });
|
|
527
534
|
return keyv;
|
|
528
535
|
}
|
|
529
536
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
|
-
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from 'redis';
|
|
3
|
-
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from 'redis';
|
|
2
|
+
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from '@redis/client';
|
|
3
|
+
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from '@redis/client';
|
|
4
4
|
import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
|
|
5
5
|
export { Keyv } from 'keyv';
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
|
-
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from 'redis';
|
|
3
|
-
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from 'redis';
|
|
2
|
+
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from '@redis/client';
|
|
3
|
+
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from '@redis/client';
|
|
4
4
|
import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
|
|
5
5
|
export { Keyv } from 'keyv';
|
|
6
6
|
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import EventEmitter from "
|
|
2
|
+
import EventEmitter from "events";
|
|
3
3
|
import {
|
|
4
4
|
createClient,
|
|
5
5
|
createCluster
|
|
6
|
-
} from "redis";
|
|
6
|
+
} from "@redis/client";
|
|
7
7
|
import { Keyv } from "keyv";
|
|
8
8
|
import calculateSlot from "cluster-key-slot";
|
|
9
9
|
import {
|
|
10
10
|
createClient as createClient2,
|
|
11
11
|
createCluster as createCluster2
|
|
12
|
-
} from "redis";
|
|
12
|
+
} from "@redis/client";
|
|
13
13
|
import {
|
|
14
14
|
Keyv as Keyv2
|
|
15
15
|
} from "keyv";
|
|
@@ -56,9 +56,12 @@ var KeyvRedis = class extends EventEmitter {
|
|
|
56
56
|
* Get the options for the adapter.
|
|
57
57
|
*/
|
|
58
58
|
get opts() {
|
|
59
|
-
let url = "";
|
|
59
|
+
let url = "redis://localhost:6379";
|
|
60
60
|
if (this._client.options) {
|
|
61
|
-
|
|
61
|
+
const redisUrl = this._client.options?.url;
|
|
62
|
+
if (redisUrl) {
|
|
63
|
+
url = redisUrl;
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
const results = {
|
|
64
67
|
namespace: this._namespace,
|
|
@@ -113,7 +116,11 @@ var KeyvRedis = class extends EventEmitter {
|
|
|
113
116
|
* Set the number of keys to delete in a single batch.
|
|
114
117
|
*/
|
|
115
118
|
set clearBatchSize(value) {
|
|
116
|
-
|
|
119
|
+
if (value > 0) {
|
|
120
|
+
this._clearBatchSize = value;
|
|
121
|
+
} else {
|
|
122
|
+
this.emit("error", "clearBatchSize must be greater than 0");
|
|
123
|
+
}
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
119
126
|
* Get if Unlink is used instead of Del for clearing keys. This is more performant but may not be supported by all Redis versions.
|
|
@@ -471,10 +478,10 @@ var KeyvRedis = class extends EventEmitter {
|
|
|
471
478
|
if (options.namespace) {
|
|
472
479
|
this._namespace = options.namespace;
|
|
473
480
|
}
|
|
474
|
-
if (options.keyPrefixSeparator) {
|
|
481
|
+
if (options.keyPrefixSeparator !== void 0) {
|
|
475
482
|
this._keyPrefixSeparator = options.keyPrefixSeparator;
|
|
476
483
|
}
|
|
477
|
-
if (options.clearBatchSize) {
|
|
484
|
+
if (options.clearBatchSize !== void 0 && options.clearBatchSize > 0) {
|
|
478
485
|
this._clearBatchSize = options.clearBatchSize;
|
|
479
486
|
}
|
|
480
487
|
if (options.useUnlink !== void 0) {
|
|
@@ -493,7 +500,7 @@ var KeyvRedis = class extends EventEmitter {
|
|
|
493
500
|
function createKeyv(connect, options) {
|
|
494
501
|
connect ??= "redis://localhost:6379";
|
|
495
502
|
const adapter = new KeyvRedis(connect, options);
|
|
496
|
-
const keyv = new Keyv(
|
|
503
|
+
const keyv = new Keyv(adapter, { namespace: options?.namespace, useKeyPrefix: false });
|
|
497
504
|
return keyv;
|
|
498
505
|
}
|
|
499
506
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/redis",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "Redis storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -34,20 +34,20 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"@redis/client": "^1.6.0",
|
|
38
|
+
"cluster-key-slot": "^1.1.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"keyv": "^5.3.
|
|
41
|
+
"keyv": "^5.3.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@vitest/coverage-v8": "^3.
|
|
44
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
45
45
|
"rimraf": "^6.0.1",
|
|
46
46
|
"timekeeper": "^2.3.1",
|
|
47
|
-
"tsd": "^0.
|
|
48
|
-
"vitest": "^3.
|
|
49
|
-
"xo": "^
|
|
50
|
-
"@keyv/test-suite": "^2.0.
|
|
47
|
+
"tsd": "^0.32.0",
|
|
48
|
+
"vitest": "^3.2.3",
|
|
49
|
+
"xo": "^1.1.0",
|
|
50
|
+
"@keyv/test-suite": "^2.0.8"
|
|
51
51
|
},
|
|
52
52
|
"tsd": {
|
|
53
53
|
"directory": "test"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
64
64
|
"test": "xo --fix && vitest run --coverage",
|
|
65
|
-
"test:ci": "xo && vitest --run --sequence.setupFiles=list",
|
|
65
|
+
"test:ci": "xo && vitest --run --sequence.setupFiles=list --coverage",
|
|
66
66
|
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
67
67
|
}
|
|
68
68
|
}
|