@keyv/redis 5.1.4 → 5.1.6
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 +8 -0
- package/dist/index.cjs +6 -1
- package/dist/index.js +6 -1
- package/package.json +20 -14
package/README.md
CHANGED
|
@@ -218,6 +218,14 @@ const keyv = createKeyvNonBlocking('redis://user:pass@localhost:6379');
|
|
|
218
218
|
|
|
219
219
|
# Namespaces
|
|
220
220
|
|
|
221
|
+
By default namespacing is turned off, this is done because it causes much more memory / performance usage for Redis.
|
|
222
|
+
|
|
223
|
+
Redis does **not** treat colons (`:`) or namespaces as special—there are no hierarchical keys or namespace mechanics internally. The dramatic memory savings you see when removing prefixes like `namespace:` come from one thing: **key length**. Redis stores every key as a full string in memory, wrapped in an SDS structure and allocated by jemalloc. Longer keys (e.g., `namespace:key123`) fall into larger jemalloc size classes, require more bytes for the SDS header, and cause more fragmentation. Shorter keys (e.g., `key123`) fit into much smaller slabs, pack tightly, and result in far more stable and predictable memory usage.
|
|
224
|
+
|
|
225
|
+
This means the colon is not the issue—**the extra characters are.** A key that goes from ~18 bytes to ~6 bytes can use *half the memory per key* once overhead, allocator classes, and fragmentation are considered. Multiply that by hundreds of thousands or millions of keys, and memory usage becomes significantly smaller and much more stable simply because the keys are shorter.
|
|
226
|
+
|
|
227
|
+
## How to use Namespaces
|
|
228
|
+
|
|
221
229
|
You can set a namespace for your keys. This is useful if you want to manage your keys in a more organized way. Here is an example of how to set a `namespace` with the `store` option:
|
|
222
230
|
|
|
223
231
|
```js
|
package/dist/index.cjs
CHANGED
|
@@ -107,7 +107,7 @@ function createKeyvNonBlocking(connect, options) {
|
|
|
107
107
|
|
|
108
108
|
// src/index.ts
|
|
109
109
|
var KeyvRedis = class extends import_hookified.Hookified {
|
|
110
|
-
_client
|
|
110
|
+
_client;
|
|
111
111
|
_namespace;
|
|
112
112
|
_keyPrefixSeparator = "::";
|
|
113
113
|
_clearBatchSize = 1e3;
|
|
@@ -154,6 +154,8 @@ var KeyvRedis = class extends import_hookified.Hookified {
|
|
|
154
154
|
this._client = (0, import_client.createCluster)(connect);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
} else {
|
|
158
|
+
this._client = (0, import_client.createClient)({ socket });
|
|
157
159
|
}
|
|
158
160
|
this.setOptions(options);
|
|
159
161
|
this.initClient();
|
|
@@ -870,6 +872,9 @@ var KeyvRedis = class extends import_hookified.Hookified {
|
|
|
870
872
|
}
|
|
871
873
|
}
|
|
872
874
|
initClient() {
|
|
875
|
+
this._client.on("error", (error) => {
|
|
876
|
+
this.emit("error", error);
|
|
877
|
+
});
|
|
873
878
|
this._client.on("connect", () => {
|
|
874
879
|
this.emit("connect", this._client);
|
|
875
880
|
});
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,7 @@ function createKeyvNonBlocking(connect, options) {
|
|
|
73
73
|
|
|
74
74
|
// src/index.ts
|
|
75
75
|
var KeyvRedis = class extends Hookified {
|
|
76
|
-
_client
|
|
76
|
+
_client;
|
|
77
77
|
_namespace;
|
|
78
78
|
_keyPrefixSeparator = "::";
|
|
79
79
|
_clearBatchSize = 1e3;
|
|
@@ -120,6 +120,8 @@ var KeyvRedis = class extends Hookified {
|
|
|
120
120
|
this._client = createCluster(connect);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
+
} else {
|
|
124
|
+
this._client = createClient({ socket });
|
|
123
125
|
}
|
|
124
126
|
this.setOptions(options);
|
|
125
127
|
this.initClient();
|
|
@@ -836,6 +838,9 @@ var KeyvRedis = class extends Hookified {
|
|
|
836
838
|
}
|
|
837
839
|
}
|
|
838
840
|
initClient() {
|
|
841
|
+
this._client.on("error", (error) => {
|
|
842
|
+
this.emit("error", error);
|
|
843
|
+
});
|
|
839
844
|
this._client.on("connect", () => {
|
|
840
845
|
this.emit("connect", this._client);
|
|
841
846
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/redis",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.6",
|
|
4
4
|
"description": "Redis storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"require":
|
|
12
|
-
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
@@ -34,21 +40,21 @@
|
|
|
34
40
|
},
|
|
35
41
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
36
42
|
"dependencies": {
|
|
37
|
-
"@redis/client": "^5.
|
|
43
|
+
"@redis/client": "^5.10.0",
|
|
38
44
|
"cluster-key-slot": "^1.1.2",
|
|
39
|
-
"hookified": "^1.
|
|
45
|
+
"hookified": "^1.13.0"
|
|
40
46
|
},
|
|
41
47
|
"peerDependencies": {
|
|
42
|
-
"keyv": "^5.
|
|
48
|
+
"keyv": "^5.6.0"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"@biomejs/biome": "^2.3.
|
|
46
|
-
"@faker-js/faker": "^10.
|
|
47
|
-
"@vitest/coverage-v8": "^4.0.
|
|
48
|
-
"rimraf": "^6.1.
|
|
51
|
+
"@biomejs/biome": "^2.3.11",
|
|
52
|
+
"@faker-js/faker": "^10.2.0",
|
|
53
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
54
|
+
"rimraf": "^6.1.2",
|
|
49
55
|
"timekeeper": "^2.3.1",
|
|
50
56
|
"tsd": "^0.33.0",
|
|
51
|
-
"vitest": "^4.0.
|
|
57
|
+
"vitest": "^4.0.16",
|
|
52
58
|
"@keyv/test-suite": "^2.1.2"
|
|
53
59
|
},
|
|
54
60
|
"tsd": {
|