@holo-js/cache-redis 0.3.28 → 0.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/LICENSE +21 -0
- package/dist/.holo-build-fingerprint +1 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.mjs +4 -19
- package/package.json +16 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Holo-JS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d6ce9ba797cfd17f0dac812d43acd6a06ccf53cb1c8b0aea3632f6ca35be429c
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ type RedisClusterNode = {
|
|
|
13
13
|
type RedisCacheDriverOptions = {
|
|
14
14
|
readonly name: string;
|
|
15
15
|
readonly connectionName: string;
|
|
16
|
-
readonly prefix: string;
|
|
17
16
|
readonly redis: {
|
|
18
17
|
readonly username?: string;
|
|
19
18
|
readonly password?: string;
|
|
@@ -70,13 +69,12 @@ type RedisClusterStartupNode = {
|
|
|
70
69
|
type RedisClusterOptions = {
|
|
71
70
|
readonly redisOptions: RedisClientOptions;
|
|
72
71
|
};
|
|
73
|
-
type RedisClientLike = Pick<Redis, 'get' | 'set' | 'del' | '
|
|
72
|
+
type RedisClientLike = Pick<Redis, 'get' | 'set' | 'del' | 'flushdb' | 'incrby' | 'decrby' | 'eval' | 'disconnect'> & {
|
|
74
73
|
readonly isCluster?: boolean;
|
|
75
74
|
nodes?(role: 'master'): readonly RedisClientLike[];
|
|
76
75
|
};
|
|
77
76
|
declare function isRedisSocketConnectionTarget(value: string): boolean;
|
|
78
77
|
declare function toRedisSocketPath(value: string): string;
|
|
79
|
-
declare function escapeRedisGlob(value: string): string;
|
|
80
78
|
declare function createRedisClientOptions(options: RedisCacheDriverOptions): RedisClientOptions;
|
|
81
79
|
declare function parseClusterNodeUrl(url: string, label: string): RedisClusterStartupNode;
|
|
82
80
|
declare function resolveClusterStartupNodes(options: RedisCacheDriverOptions): readonly RedisClusterStartupNode[];
|
|
@@ -96,7 +94,6 @@ declare const redisCacheDriverInternals: {
|
|
|
96
94
|
createRedisClientOptions: typeof createRedisClientOptions;
|
|
97
95
|
createRedisClusterOptions: typeof createRedisClusterOptions;
|
|
98
96
|
createRedisLock: typeof createRedisLock;
|
|
99
|
-
escapeRedisGlob: typeof escapeRedisGlob;
|
|
100
97
|
isRedisSocketConnectionTarget: typeof isRedisSocketConnectionTarget;
|
|
101
98
|
isRedisNumericMutationError: typeof isRedisNumericMutationError;
|
|
102
99
|
parseClusterNodeUrl: typeof parseClusterNodeUrl;
|
|
@@ -105,4 +102,5 @@ declare const redisCacheDriverInternals: {
|
|
|
105
102
|
toRedisSocketPath: typeof toRedisSocketPath;
|
|
106
103
|
};
|
|
107
104
|
|
|
108
|
-
export {
|
|
105
|
+
export { createRedisCacheDriver, redisCacheDriverFactory, redisCacheDriverInternals };
|
|
106
|
+
export type { RedisCacheDriverOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
CacheInvalidNumericMutationError,
|
|
6
6
|
registerCacheDriverFactory
|
|
7
7
|
} from "@holo-js/cache";
|
|
8
|
-
var REDIS_SCAN_COUNT = 100;
|
|
9
8
|
var CACHE_DRIVER_DISPOSE_SYMBOL = /* @__PURE__ */ Symbol.for("holo.cache.driver.dispose");
|
|
10
9
|
var RELEASE_LOCK_SCRIPT = [
|
|
11
10
|
'if redis.call("get", KEYS[1]) == ARGV[1] then',
|
|
@@ -24,9 +23,6 @@ function isRedisSocketConnectionTarget(value) {
|
|
|
24
23
|
function toRedisSocketPath(value) {
|
|
25
24
|
return value.startsWith("unix://") ? value.slice("unix://".length) : value;
|
|
26
25
|
}
|
|
27
|
-
function escapeRedisGlob(value) {
|
|
28
|
-
return value.replace(/[\\*?[\]]/g, (match) => `\\${match}`);
|
|
29
|
-
}
|
|
30
26
|
function isRedisUrl(value) {
|
|
31
27
|
return value.startsWith("redis://") || value.startsWith("rediss://");
|
|
32
28
|
}
|
|
@@ -63,7 +59,8 @@ function parseClusterNodeUrl(url, label) {
|
|
|
63
59
|
};
|
|
64
60
|
} catch (error) {
|
|
65
61
|
throw new Error(
|
|
66
|
-
`[@holo-js/cache-redis] ${label} is invalid: ${error instanceof Error ? error.message : String(error)}
|
|
62
|
+
`[@holo-js/cache-redis] ${label} is invalid: ${error instanceof Error ? error.message : String(error)}`,
|
|
63
|
+
{ cause: error }
|
|
67
64
|
);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -173,17 +170,6 @@ function createRedisCacheDriver(options) {
|
|
|
173
170
|
const sleep = options.sleep ?? defaultSleep;
|
|
174
171
|
const ownerFactory = options.ownerFactory ?? randomUUID;
|
|
175
172
|
const now = options.now ?? Date.now;
|
|
176
|
-
const flushPattern = `${escapeRedisGlob(options.prefix)}*`;
|
|
177
|
-
async function flushClient(target) {
|
|
178
|
-
let cursor = "0";
|
|
179
|
-
do {
|
|
180
|
-
const [nextCursor, keys] = await target.scan(cursor, "MATCH", flushPattern, "COUNT", REDIS_SCAN_COUNT);
|
|
181
|
-
cursor = nextCursor;
|
|
182
|
-
if (keys.length > 0) {
|
|
183
|
-
await Promise.all(keys.map(async (key) => target.del(key)));
|
|
184
|
-
}
|
|
185
|
-
} while (cursor !== "0");
|
|
186
|
-
}
|
|
187
173
|
async function mutateNumericValue(key, amount, mutate) {
|
|
188
174
|
try {
|
|
189
175
|
return await mutate(key, amount);
|
|
@@ -234,11 +220,11 @@ function createRedisCacheDriver(options) {
|
|
|
234
220
|
async flush() {
|
|
235
221
|
if (client.isCluster) {
|
|
236
222
|
for (const node of client.nodes?.("master") ?? []) {
|
|
237
|
-
await
|
|
223
|
+
await node.flushdb();
|
|
238
224
|
}
|
|
239
225
|
return;
|
|
240
226
|
}
|
|
241
|
-
await
|
|
227
|
+
await client.flushdb();
|
|
242
228
|
},
|
|
243
229
|
async increment(key, amount) {
|
|
244
230
|
return await mutateNumericValue(key, amount, async (targetKey, targetAmount) => await client.incrby(targetKey, targetAmount));
|
|
@@ -268,7 +254,6 @@ var redisCacheDriverInternals = {
|
|
|
268
254
|
createRedisClientOptions,
|
|
269
255
|
createRedisClusterOptions,
|
|
270
256
|
createRedisLock,
|
|
271
|
-
escapeRedisGlob,
|
|
272
257
|
isRedisSocketConnectionTarget,
|
|
273
258
|
isRedisNumericMutationError,
|
|
274
259
|
parseClusterNodeUrl,
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/cache-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Holo-JS Framework - Redis cache driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/cobraprojects/holo-js.git",
|
|
10
|
+
"directory": "packages/cache-redis"
|
|
11
|
+
},
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
14
|
"types": "./dist/index.d.ts",
|
|
@@ -14,7 +19,8 @@
|
|
|
14
19
|
"main": "./dist/index.mjs",
|
|
15
20
|
"types": "./dist/index.d.ts",
|
|
16
21
|
"files": [
|
|
17
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE"
|
|
18
24
|
],
|
|
19
25
|
"scripts": {
|
|
20
26
|
"build": "tsup",
|
|
@@ -24,20 +30,20 @@
|
|
|
24
30
|
"test:integration": "HOLO_REDIS_INTEGRATION=1 vitest --run"
|
|
25
31
|
},
|
|
26
32
|
"peerDependencies": {
|
|
27
|
-
"@holo-js/cache": "^0.
|
|
33
|
+
"@holo-js/cache": "^0.4.1"
|
|
28
34
|
},
|
|
29
35
|
"dependencies": {
|
|
30
|
-
"ioredis": "^
|
|
36
|
+
"ioredis": "^6.0.0",
|
|
31
37
|
"tslib": "^2.8.1"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
34
|
-
"@holo-js/cache": "^0.
|
|
35
|
-
"@types/node": "^22.
|
|
36
|
-
"tsup": "^
|
|
37
|
-
"typescript": "^
|
|
38
|
-
"vitest": "^
|
|
40
|
+
"@holo-js/cache": "^0.4.1",
|
|
41
|
+
"@types/node": "^22.20.5",
|
|
42
|
+
"tsup": "^9.0.0",
|
|
43
|
+
"typescript": "^6.0.3",
|
|
44
|
+
"vitest": "^5.0.5"
|
|
39
45
|
},
|
|
40
46
|
"engines": {
|
|
41
|
-
"node": "^22.
|
|
47
|
+
"node": "^22.18.0 || ^24.0.0 || ^26.0.0"
|
|
42
48
|
}
|
|
43
49
|
}
|