tricache 1.0.1 → 2.0.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 +89 -93
- package/dashboards/tricache-alerts.yaml +80 -4
- package/dashboards/tricache-grafana.json +54 -1
- package/dashboards/tricache-inventory.rules.yml +21 -0
- package/dist/cache-service-BV5T8-20.d.cts +1064 -0
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
- package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
- package/dist/chunk-RBJRTGFK.js +94 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +3694 -1070
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +210 -14
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +3578 -1068
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +368 -162
- package/dist/edge/index.d.cts +134 -0
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +314 -155
- package/dist/hono/index.cjs +3614 -1087
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/hono-CMv2VdQ6.d.cts +404 -0
- package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
- package/dist/http/index.cjs +3712 -1124
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +92 -43
- package/dist/index.cjs +4067 -1252
- package/dist/index.d.cts +1071 -0
- package/dist/index.d.ts +123 -27
- package/dist/index.js +878 -21
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/murmur3-DF8BFRnu.d.ts +99 -0
- package/dist/nestjs/index.cjs +3635 -1112
- package/dist/nestjs/index.d.cts +299 -0
- package/dist/nestjs/index.d.ts +120 -33
- package/dist/nestjs/index.js +132 -43
- package/dist/next/index.cjs +3704 -1175
- package/dist/next/index.d.cts +238 -0
- package/dist/next/index.d.ts +39 -11
- package/dist/next/index.js +202 -102
- package/dist/prisma/index.cjs +29 -18
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +17 -18
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
- package/dist/types-F8vRWMrE.d.ts +1636 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +116 -37
- package/src/adapters/auto-pipeliner.ts +150 -26
- package/src/adapters/node-redis.ts +106 -27
- package/src/cache-service.ts +2215 -793
- package/src/cli.ts +25 -14
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +22 -4
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +448 -102
- package/src/drizzle/index.ts +2 -1
- package/src/edge/adapters/cloudflare-do.ts +25 -10
- package/src/edge/adapters/cloudflare-kv.ts +12 -9
- package/src/edge/adapters/upstash.ts +27 -11
- package/src/edge/cache.ts +200 -110
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +17 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +62 -17
- package/src/http/fastify.ts +35 -21
- package/src/http/utils.ts +60 -20
- package/src/index.ts +6 -0
- package/src/ipc-telemetry.ts +35 -9
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +15 -12
- package/src/nestjs/tricache.store.ts +69 -26
- package/src/nestjs/types.ts +30 -16
- package/src/next/cache-handler.ts +151 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +25 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +17 -24
- package/src/remote-snapshot.ts +37 -27
- package/src/serialize-worker.ts +8 -5
- package/src/sigv4-snapshot-adapter.ts +37 -27
- package/src/smart-memory-cache.ts +121 -44
- package/src/types.ts +117 -37
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/lz4-size.ts +74 -0
- package/src/utils/namespace-key.ts +48 -0
- package/src/utils/query-key.ts +13 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/utils/snapshot-transfer.ts +83 -0
- package/src/utils/work-limits.ts +73 -0
- package/src/utils/write-revision.ts +4 -0
- package/src/wasm/bloom-filter-wasm.ts +25 -5
- package/src/worker-pool.ts +44 -15
- package/src/wtiny-lfu.ts +82 -20
- package/dist/cache-service-MG7PN6MX.js +0 -12
- package/dist/chunk-3I5L7K6I.js +0 -704
- package/dist/chunk-BQRURGGD.js +0 -60
|
@@ -9,92 +9,127 @@ export type { IRedisDriver, IRedisPipeline };
|
|
|
9
9
|
*/
|
|
10
10
|
export class NodeRedisPipelineAdapter implements IRedisPipeline {
|
|
11
11
|
private readonly multiInstance: any;
|
|
12
|
+
private readonly operations: Array<() => Promise<unknown>> = [];
|
|
13
|
+
pttl?: (key: string) => this;
|
|
14
|
+
eval?: (script: string, numkeys: number, ...args: (string | number)[]) => this;
|
|
12
15
|
|
|
13
|
-
constructor(multiInstance: any) {
|
|
16
|
+
constructor(multiInstance: any, private readonly transactional = true) {
|
|
14
17
|
this.multiInstance = multiInstance;
|
|
18
|
+
if (typeof multiInstance.pTTL === 'function' || typeof multiInstance.pttl === 'function') {
|
|
19
|
+
this.pttl = key => { this.queueCommand(typeof multiInstance.pTTL === 'function' ? 'pTTL' : 'pttl', [key]); return this; };
|
|
20
|
+
}
|
|
21
|
+
if (typeof multiInstance.eval === 'function' || typeof multiInstance.addCommand === 'function') {
|
|
22
|
+
this.eval = (script, numkeys, ...args) => {
|
|
23
|
+
if (typeof multiInstance.eval === 'function') {
|
|
24
|
+
this.queueCommand('eval', [script, { keys: args.slice(0, numkeys).map(String), arguments: args.slice(numkeys).map(String) }]);
|
|
25
|
+
} else this.queueCommand('addCommand', [['EVAL', script, String(numkeys), ...args.map(String)]]);
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private queueCommand(method: string, args: unknown[]): void {
|
|
32
|
+
if (this.transactional) this.multiInstance[method](...args);
|
|
33
|
+
else this.operations.push(() => this.multiInstance[method](...args));
|
|
15
34
|
}
|
|
16
35
|
|
|
17
36
|
get(key: string): this {
|
|
18
|
-
this.
|
|
37
|
+
this.queueCommand('get', [key]);
|
|
19
38
|
return this;
|
|
20
39
|
}
|
|
21
40
|
|
|
22
41
|
set(key: string, value: string, ...args: (string | number)[]): this {
|
|
23
42
|
const opts = parseSetArgs(args);
|
|
24
43
|
if (opts) {
|
|
25
|
-
this.
|
|
44
|
+
this.queueCommand('set', [key, value, opts]);
|
|
26
45
|
} else {
|
|
27
|
-
this.
|
|
46
|
+
this.queueCommand('set', [key, value]);
|
|
28
47
|
}
|
|
29
48
|
return this;
|
|
30
49
|
}
|
|
31
50
|
|
|
32
51
|
setex(key: string, seconds: number, value: string): this {
|
|
33
52
|
if (typeof this.multiInstance.setEx === 'function') {
|
|
34
|
-
this.
|
|
53
|
+
this.queueCommand('setEx', [key, seconds, value]);
|
|
35
54
|
} else if (typeof this.multiInstance.setex === 'function') {
|
|
36
|
-
this.
|
|
55
|
+
this.queueCommand('setex', [key, seconds, value]);
|
|
37
56
|
} else {
|
|
38
|
-
this.
|
|
57
|
+
this.queueCommand('set', [key, value, { EX: seconds }]);
|
|
39
58
|
}
|
|
40
59
|
return this;
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
del(...keys: string[]): this {
|
|
44
63
|
if (keys.length === 0) return this;
|
|
45
|
-
this.
|
|
64
|
+
this.queueCommand('del', [keys.length === 1 ? keys[0] : keys]);
|
|
46
65
|
return this;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
expire(key: string, seconds: number): this {
|
|
50
|
-
this.
|
|
69
|
+
this.queueCommand('expire', [key, seconds]);
|
|
51
70
|
return this;
|
|
52
71
|
}
|
|
53
72
|
|
|
54
73
|
incr(key: string): this {
|
|
55
|
-
this.
|
|
74
|
+
this.queueCommand('incr', [key]);
|
|
56
75
|
return this;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
sadd(key: string, ...members: string[]): this {
|
|
60
79
|
if (members.length === 0) return this;
|
|
61
80
|
if (typeof this.multiInstance.sAdd === 'function') {
|
|
62
|
-
this.
|
|
81
|
+
this.queueCommand('sAdd', [key, members.length === 1 ? members[0] : members]);
|
|
63
82
|
} else {
|
|
64
|
-
this.
|
|
83
|
+
this.queueCommand('sadd', [key, ...members]);
|
|
65
84
|
}
|
|
66
85
|
return this;
|
|
67
86
|
}
|
|
68
87
|
|
|
69
88
|
smembers(key: string): this {
|
|
70
89
|
if (typeof this.multiInstance.sMembers === 'function') {
|
|
71
|
-
this.
|
|
90
|
+
this.queueCommand('sMembers', [key]);
|
|
72
91
|
} else {
|
|
73
|
-
this.
|
|
92
|
+
this.queueCommand('smembers', [key]);
|
|
74
93
|
}
|
|
75
94
|
return this;
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
hset(key: string, value: Record<string, string>): this {
|
|
79
98
|
if (typeof this.multiInstance.hSet === 'function') {
|
|
80
|
-
this.
|
|
99
|
+
this.queueCommand('hSet', [key, value]);
|
|
81
100
|
} else {
|
|
82
|
-
this.
|
|
101
|
+
this.queueCommand('hset', [key, value]);
|
|
83
102
|
}
|
|
84
103
|
return this;
|
|
85
104
|
}
|
|
86
105
|
|
|
87
106
|
hgetall(key: string): this {
|
|
88
107
|
if (typeof this.multiInstance.hGetAll === 'function') {
|
|
89
|
-
this.
|
|
108
|
+
this.queueCommand('hGetAll', [key]);
|
|
90
109
|
} else {
|
|
91
|
-
this.
|
|
110
|
+
this.queueCommand('hgetall', [key]);
|
|
92
111
|
}
|
|
93
112
|
return this;
|
|
94
113
|
}
|
|
95
114
|
|
|
96
115
|
async exec(): Promise<Array<[Error | null, any]> | null> {
|
|
97
|
-
|
|
116
|
+
let raw: any[] | null;
|
|
117
|
+
if (!this.transactional) {
|
|
118
|
+
// node-redis auto-pipelines same-tick commands. Observe every command
|
|
119
|
+
// separately: execAsPipeline() can reject at the first error and discard
|
|
120
|
+
// the successful replies, and retrying that pipeline could duplicate writes.
|
|
121
|
+
const results = await Promise.allSettled(this.operations.splice(0).map(operation => Promise.resolve().then(operation)));
|
|
122
|
+
return results.map(result => result.status === 'fulfilled' ? [null, result.value]
|
|
123
|
+
: [result.reason instanceof Error ? result.reason : new Error(String(result.reason)), null]);
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
raw = await this.multiInstance.exec();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
// node-redis rejects EXEC with MultiErrorReply, unlike ioredis tuples.
|
|
129
|
+
const replies = (error as { replies?: unknown[] }).replies;
|
|
130
|
+
if (!Array.isArray(replies)) throw error;
|
|
131
|
+
raw = replies;
|
|
132
|
+
}
|
|
98
133
|
if (!raw) return null;
|
|
99
134
|
return raw.map((item: any) => {
|
|
100
135
|
if (item instanceof Error) {
|
|
@@ -109,14 +144,20 @@ export class NodeRedisPipelineAdapter implements IRedisPipeline {
|
|
|
109
144
|
* Universal driver adapter wrapping `@redis/client` (node-redis) to satisfy TriCache's
|
|
110
145
|
* `IRedisDriver` contract without adding runtime dependencies.
|
|
111
146
|
*/
|
|
112
|
-
export class NodeRedisAdapter implements IRedisDriver {
|
|
147
|
+
export class NodeRedisAdapter extends EventEmitter implements IRedisDriver {
|
|
113
148
|
readonly client: any;
|
|
149
|
+
private connecting: Promise<unknown> | null = null;
|
|
150
|
+
pttl?: (key: string) => Promise<number>;
|
|
114
151
|
|
|
115
152
|
constructor(client: any) {
|
|
153
|
+
super();
|
|
116
154
|
if (!client) {
|
|
117
155
|
throw new Error('NodeRedisAdapter requires an active @redis/client instance');
|
|
118
156
|
}
|
|
119
157
|
this.client = client;
|
|
158
|
+
if (typeof client.pTTL === 'function' || typeof client.pttl === 'function') {
|
|
159
|
+
this.pttl = key => (client.pTTL ?? client.pttl).call(client, key);
|
|
160
|
+
}
|
|
120
161
|
}
|
|
121
162
|
|
|
122
163
|
get isOpen(): boolean {
|
|
@@ -124,8 +165,11 @@ export class NodeRedisAdapter implements IRedisDriver {
|
|
|
124
165
|
}
|
|
125
166
|
|
|
126
167
|
async connect(): Promise<unknown> {
|
|
168
|
+
if (this.connecting) return this.connecting;
|
|
127
169
|
if (typeof this.client.connect === 'function' && !this.client.isOpen) {
|
|
128
|
-
|
|
170
|
+
this.connecting = Promise.resolve(this.client.connect());
|
|
171
|
+
try { return await this.connecting; }
|
|
172
|
+
finally { this.connecting = null; }
|
|
129
173
|
}
|
|
130
174
|
return undefined;
|
|
131
175
|
}
|
|
@@ -216,7 +260,7 @@ export class NodeRedisAdapter implements IRedisDriver {
|
|
|
216
260
|
}
|
|
217
261
|
|
|
218
262
|
pipeline(): IRedisPipeline {
|
|
219
|
-
return this.
|
|
263
|
+
return new NodeRedisPipelineAdapter(this.client, false);
|
|
220
264
|
}
|
|
221
265
|
|
|
222
266
|
async smembers(key: string): Promise<string[]> {
|
|
@@ -277,7 +321,34 @@ export class NodeRedisAdapter implements IRedisDriver {
|
|
|
277
321
|
|
|
278
322
|
async subscribe(...channels: string[]): Promise<unknown> {
|
|
279
323
|
if (channels.length === 0) return undefined;
|
|
280
|
-
|
|
324
|
+
await this.connect();
|
|
325
|
+
return await this.client.subscribe(channels, (message: string, channel: string) => this.emit('message', channel, message));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async unsubscribe(...channels: string[]): Promise<unknown> {
|
|
329
|
+
if (!channels.length || !this.isOpen) return undefined;
|
|
330
|
+
return this.client.unsubscribe(channels);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async xread(...args: (string | number)[]): Promise<Array<[string, Array<[string, string[]]>]> | null> {
|
|
334
|
+
await this.connect();
|
|
335
|
+
const raw = await this.client.sendCommand(['XREAD', ...args.map(String)]);
|
|
336
|
+
if (raw == null) return null;
|
|
337
|
+
if (raw instanceof Map) return [...raw.entries()];
|
|
338
|
+
if (!Array.isArray(raw) && typeof raw === 'object') return Object.entries(raw);
|
|
339
|
+
return raw;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async xadd(...args: (string | number)[]): Promise<unknown> {
|
|
343
|
+
return this.client.sendCommand(['XADD', ...args.map(String)]);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async xrange(...args: (string | number)[]): Promise<Array<[string, string[]]>> {
|
|
347
|
+
return this.client.sendCommand(['XRANGE', ...args.map(String)]);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async xrevrange(...args: (string | number)[]): Promise<Array<[string, string[]]>> {
|
|
351
|
+
return this.client.sendCommand(['XREVRANGE', ...args.map(String)]);
|
|
281
352
|
}
|
|
282
353
|
|
|
283
354
|
scanStream(options?: { match?: string; count?: number }): EventEmitter {
|
|
@@ -289,8 +360,8 @@ export class NodeRedisAdapter implements IRedisDriver {
|
|
|
289
360
|
try {
|
|
290
361
|
if (typeof this.client.scanIterator === 'function') {
|
|
291
362
|
const batch: string[] = [];
|
|
292
|
-
for await (const
|
|
293
|
-
batch.push(
|
|
363
|
+
for await (const keys of this.client.scanIterator({ MATCH: pattern, COUNT: count })) {
|
|
364
|
+
batch.push(...(Array.isArray(keys) ? keys : [keys]));
|
|
294
365
|
if (batch.length >= count) {
|
|
295
366
|
ee.emit('data', [...batch]);
|
|
296
367
|
batch.length = 0;
|
|
@@ -337,18 +408,26 @@ export class NodeRedisAdapter implements IRedisDriver {
|
|
|
337
408
|
}
|
|
338
409
|
|
|
339
410
|
on(event: string, listener: (...args: any[]) => void): this {
|
|
411
|
+
if (event === 'message' || event === 'smessage') return super.on(event, listener);
|
|
340
412
|
if (typeof this.client.on === 'function') {
|
|
341
|
-
this.client.on(event, listener);
|
|
413
|
+
this.client.on(event === 'close' ? 'end' : event, listener);
|
|
342
414
|
}
|
|
343
415
|
return this;
|
|
344
416
|
}
|
|
345
417
|
|
|
346
418
|
once(event: string, listener: (...args: any[]) => void): this {
|
|
419
|
+
if (event === 'message' || event === 'smessage') return super.once(event, listener);
|
|
347
420
|
if (typeof this.client.once === 'function') {
|
|
348
|
-
this.client.once(event, listener);
|
|
421
|
+
this.client.once(event === 'close' ? 'end' : event, listener);
|
|
349
422
|
}
|
|
350
423
|
return this;
|
|
351
424
|
}
|
|
425
|
+
|
|
426
|
+
removeListener(event: string, listener: (...args: any[]) => void): this {
|
|
427
|
+
super.removeListener(event, listener);
|
|
428
|
+
this.client.removeListener?.(event === 'close' ? 'end' : event, listener);
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
352
431
|
}
|
|
353
432
|
|
|
354
433
|
/**
|