tricache 1.0.0 → 1.0.2

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.
Files changed (97) hide show
  1. package/README.md +36 -28
  2. package/dist/{cache-service-pJ-nFcVj.d.ts → cache-service-B108FzER.d.ts} +63 -3
  3. package/dist/cache-service-CWI4jkS7.d.cts +963 -0
  4. package/dist/{cache-service-26GCO3UU.js → cache-service-GYPZFB7O.js} +2 -2
  5. package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
  6. package/dist/{chunk-2AJKEQMZ.js → chunk-H4GFLQ26.js} +7 -4
  7. package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
  8. package/dist/chunk-OYDU3SMI.js +89 -0
  9. package/dist/{chunk-VXFTFZ5N.js → chunk-VNRDL5RA.js} +117 -138
  10. package/dist/{chunk-7SZSQS55.js → chunk-WYF7NOAT.js} +1831 -759
  11. package/dist/cli.cjs +1757 -777
  12. package/dist/cli.d.cts +12 -0
  13. package/dist/cli.js +27 -6
  14. package/dist/dashboard/index.cjs +111 -29
  15. package/dist/dashboard/index.d.cts +185 -0
  16. package/dist/dashboard/index.d.ts +5 -3
  17. package/dist/dashboard/index.js +1 -1
  18. package/dist/drizzle/index.cjs +1757 -773
  19. package/dist/drizzle/index.d.cts +46 -0
  20. package/dist/drizzle/index.d.ts +2 -2
  21. package/dist/drizzle/index.js +1 -1
  22. package/dist/edge/index.cjs +280 -153
  23. package/dist/edge/index.d.cts +127 -0
  24. package/dist/edge/index.d.ts +3 -3
  25. package/dist/edge/index.js +254 -147
  26. package/dist/hono/index.cjs +1805 -793
  27. package/dist/hono/index.d.cts +93 -0
  28. package/dist/hono/index.d.ts +7 -5
  29. package/dist/hono/index.js +16 -9
  30. package/dist/{hono-DuNvciyq.d.ts → hono-3rDMYVtY.d.ts} +23 -3
  31. package/dist/hono-C886ok3X.d.cts +391 -0
  32. package/dist/http/index.cjs +1946 -842
  33. package/dist/http/index.d.cts +103 -0
  34. package/dist/http/index.d.ts +13 -5
  35. package/dist/http/index.js +137 -57
  36. package/dist/index.cjs +2073 -937
  37. package/dist/index.d.cts +1006 -0
  38. package/dist/index.d.ts +40 -8
  39. package/dist/index.js +8 -8
  40. package/dist/murmur3-CMGw9PbV.d.cts +98 -0
  41. package/dist/nestjs/index.cjs +1849 -806
  42. package/dist/nestjs/index.d.cts +285 -0
  43. package/dist/nestjs/index.d.ts +103 -30
  44. package/dist/nestjs/index.js +115 -32
  45. package/dist/next/index.cjs +1913 -887
  46. package/dist/next/index.d.cts +232 -0
  47. package/dist/next/index.d.ts +33 -11
  48. package/dist/next/index.js +174 -107
  49. package/dist/prisma/index.cjs +11 -1
  50. package/dist/prisma/index.d.cts +62 -0
  51. package/dist/prisma/index.d.ts +2 -2
  52. package/dist/prisma/index.js +11 -1
  53. package/dist/serialize-worker.d.cts +2 -0
  54. package/dist/{types-5HXqBfAf.d.ts → types-BA4pz1A0.d.cts} +26 -9
  55. package/dist/types-BA4pz1A0.d.ts +1519 -0
  56. package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
  57. package/dist/utils-Bvzn-rKS.d.ts +29 -0
  58. package/package.json +96 -36
  59. package/src/adapters/auto-pipeliner.ts +107 -24
  60. package/src/adapters/node-redis.ts +123 -25
  61. package/src/cache-service.ts +1238 -659
  62. package/src/cli.ts +24 -6
  63. package/src/cross-region.ts +21 -3
  64. package/src/dashboard/handler.ts +26 -6
  65. package/src/dashboard/html.ts +35 -10
  66. package/src/dashboard/index.ts +35 -13
  67. package/src/dashboard/types.ts +3 -1
  68. package/src/disk-tier.ts +171 -65
  69. package/src/edge/cache.ts +202 -129
  70. package/src/edge/hono.ts +23 -6
  71. package/src/edge/types.ts +2 -0
  72. package/src/hono/index.ts +19 -9
  73. package/src/http/express.ts +110 -26
  74. package/src/http/fastify.ts +38 -28
  75. package/src/http/utils.ts +54 -20
  76. package/src/ipc-telemetry.ts +35 -9
  77. package/src/nestjs/decorators.ts +1 -1
  78. package/src/nestjs/index.ts +2 -0
  79. package/src/nestjs/keyv-adapter.ts +68 -0
  80. package/src/nestjs/tricache.module.ts +13 -11
  81. package/src/nestjs/tricache.store.ts +51 -20
  82. package/src/nestjs/types.ts +29 -15
  83. package/src/next/cache-handler.ts +132 -57
  84. package/src/next/index.ts +1 -0
  85. package/src/next/isr-handler.ts +1 -4
  86. package/src/next/types.ts +21 -0
  87. package/src/prisma/index.ts +12 -1
  88. package/src/smart-memory-cache.ts +65 -27
  89. package/src/types.ts +27 -2
  90. package/src/utils/cgroup.ts +12 -0
  91. package/src/utils/deadline.ts +14 -0
  92. package/src/utils/diagnostics.ts +27 -0
  93. package/src/utils/redis-slot.ts +13 -0
  94. package/src/wasm/bloom-filter-wasm.ts +9 -4
  95. package/src/worker-pool.ts +17 -8
  96. package/src/wtiny-lfu.ts +20 -6
  97. package/dist/chunk-BQRURGGD.js +0 -60
@@ -3,6 +3,8 @@ interface KeyDerivationOptions {
3
3
  keyGenerator?: (req: any) => string;
4
4
  /** Optional list of header names (case-insensitive) to include in the cache key. */
5
5
  headerWhitelist?: string[];
6
+ /** Opt in to authenticated request caching with an identity-aware key. Default: false. */
7
+ cacheAuthenticated?: boolean;
6
8
  }
7
9
  /**
8
10
  * Generates a deterministic HTTP cache key from request method, URL path, sorted query parameters,
@@ -18,7 +20,7 @@ declare function buildDeterministicKey(req: any, options?: KeyDerivationOptions)
18
20
  * Checks if request specifies Cache-Control bypass directives (no-cache, no-store)
19
21
  * or matches a custom skipCache predicate.
20
22
  */
21
- declare function shouldSkipCache(req: any, customSkip?: (req: any) => boolean): boolean;
23
+ declare function shouldSkipCache(req: any, customSkip?: (req: any) => boolean, options?: KeyDerivationOptions): boolean;
22
24
  /**
23
25
  * Compute a weak ETag (W/"...") from string, Buffer, or JSON-serializable object.
24
26
  */
@@ -0,0 +1,29 @@
1
+ interface KeyDerivationOptions {
2
+ /** Custom key derivation function. Overrides default URL and query string serialization. */
3
+ keyGenerator?: (req: any) => string;
4
+ /** Optional list of header names (case-insensitive) to include in the cache key. */
5
+ headerWhitelist?: string[];
6
+ /** Opt in to authenticated request caching with an identity-aware key. Default: false. */
7
+ cacheAuthenticated?: boolean;
8
+ }
9
+ /**
10
+ * Generates a deterministic HTTP cache key from request method, URL path, sorted query parameters,
11
+ * and optional whitelisted headers.
12
+ *
13
+ * Example:
14
+ * GET /api/products?sort=desc&page=2
15
+ * GET /api/products?page=2&sort=desc
16
+ * Both map to: http:GET:/api/products?page=2&sort=desc
17
+ */
18
+ declare function buildDeterministicKey(req: any, options?: KeyDerivationOptions): string;
19
+ /**
20
+ * Checks if request specifies Cache-Control bypass directives (no-cache, no-store)
21
+ * or matches a custom skipCache predicate.
22
+ */
23
+ declare function shouldSkipCache(req: any, customSkip?: (req: any) => boolean, options?: KeyDerivationOptions): boolean;
24
+ /**
25
+ * Compute a weak ETag (W/"...") from string, Buffer, or JSON-serializable object.
26
+ */
27
+ declare function generateETag(data: unknown): string;
28
+
29
+ export { type KeyDerivationOptions as K, buildDeterministicKey as b, generateETag as g, shouldSkipCache as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tricache",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Three-tier Node.js cache: L1 smart RAM (adaptive LFU/LRU + Count-Min Sketch) → L1.5 NVMe disk spill → L2 Redis/Valkey. Includes AES-256-GCM at-rest encryption, WASM Bloom filter, Stale-While-Revalidate, and thundering-herd prevention.",
5
5
  "keywords": [
6
6
  "cache",
@@ -40,51 +40,102 @@
40
40
  },
41
41
  "exports": {
42
42
  ".": {
43
- "types": "./dist/index.d.ts",
44
- "import": "./dist/index.js",
45
- "require": "./dist/index.cjs"
43
+ "import": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/index.d.cts",
49
+ "default": "./dist/index.cjs"
50
+ }
46
51
  },
47
52
  "./next": {
48
- "types": "./dist/next/index.d.ts",
49
- "import": "./dist/next/index.js",
50
- "require": "./dist/next/index.cjs"
53
+ "import": {
54
+ "types": "./dist/next/index.d.ts",
55
+ "default": "./dist/next/index.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/next/index.d.cts",
59
+ "default": "./dist/next/index.cjs"
60
+ }
51
61
  },
52
62
  "./nestjs": {
53
- "types": "./dist/nestjs/index.d.ts",
54
- "import": "./dist/nestjs/index.js",
55
- "require": "./dist/nestjs/index.cjs"
63
+ "import": {
64
+ "types": "./dist/nestjs/index.d.ts",
65
+ "default": "./dist/nestjs/index.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/nestjs/index.d.cts",
69
+ "default": "./dist/nestjs/index.cjs"
70
+ }
56
71
  },
57
72
  "./prisma": {
58
- "types": "./dist/prisma/index.d.ts",
59
- "import": "./dist/prisma/index.js",
60
- "require": "./dist/prisma/index.cjs"
73
+ "import": {
74
+ "types": "./dist/prisma/index.d.ts",
75
+ "default": "./dist/prisma/index.js"
76
+ },
77
+ "require": {
78
+ "types": "./dist/prisma/index.d.cts",
79
+ "default": "./dist/prisma/index.cjs"
80
+ }
61
81
  },
62
82
  "./drizzle": {
63
- "types": "./dist/drizzle/index.d.ts",
64
- "import": "./dist/drizzle/index.js",
65
- "require": "./dist/drizzle/index.cjs"
83
+ "import": {
84
+ "types": "./dist/drizzle/index.d.ts",
85
+ "default": "./dist/drizzle/index.js"
86
+ },
87
+ "require": {
88
+ "types": "./dist/drizzle/index.d.cts",
89
+ "default": "./dist/drizzle/index.cjs"
90
+ }
66
91
  },
67
92
  "./http": {
68
- "types": "./dist/http/index.d.ts",
69
- "import": "./dist/http/index.js",
70
- "require": "./dist/http/index.cjs"
93
+ "import": {
94
+ "types": "./dist/http/index.d.ts",
95
+ "default": "./dist/http/index.js"
96
+ },
97
+ "require": {
98
+ "types": "./dist/http/index.d.cts",
99
+ "default": "./dist/http/index.cjs"
100
+ }
71
101
  },
72
102
  "./hono": {
73
- "types": "./dist/hono/index.d.ts",
74
- "import": "./dist/hono/index.js",
75
- "require": "./dist/hono/index.cjs"
103
+ "import": {
104
+ "types": "./dist/hono/index.d.ts",
105
+ "default": "./dist/hono/index.js"
106
+ },
107
+ "require": {
108
+ "types": "./dist/hono/index.d.cts",
109
+ "default": "./dist/hono/index.cjs"
110
+ }
76
111
  },
77
112
  "./dashboard": {
78
- "types": "./dist/dashboard/index.d.ts",
79
- "import": "./dist/dashboard/index.js",
80
- "require": "./dist/dashboard/index.cjs"
113
+ "import": {
114
+ "types": "./dist/dashboard/index.d.ts",
115
+ "default": "./dist/dashboard/index.js"
116
+ },
117
+ "require": {
118
+ "types": "./dist/dashboard/index.d.cts",
119
+ "default": "./dist/dashboard/index.cjs"
120
+ }
81
121
  },
82
122
  "./edge": {
83
- "types": "./dist/edge/index.d.ts",
84
- "edge-light": "./dist/edge/index.js",
85
- "workerd": "./dist/edge/index.js",
86
- "import": "./dist/edge/index.js",
87
- "require": "./dist/edge/index.cjs",
123
+ "edge-light": {
124
+ "types": "./dist/edge/index.d.ts",
125
+ "default": "./dist/edge/index.js"
126
+ },
127
+ "workerd": {
128
+ "types": "./dist/edge/index.d.ts",
129
+ "default": "./dist/edge/index.js"
130
+ },
131
+ "import": {
132
+ "types": "./dist/edge/index.d.ts",
133
+ "default": "./dist/edge/index.js"
134
+ },
135
+ "require": {
136
+ "types": "./dist/edge/index.d.cts",
137
+ "default": "./dist/edge/index.cjs"
138
+ },
88
139
  "default": "./dist/edge/index.js"
89
140
  }
90
141
  },
@@ -97,8 +148,8 @@
97
148
  "LICENSE"
98
149
  ],
99
150
  "peerDependencies": {
100
- "@nestjs/common": "^10.0.0 || ^11.0.0",
101
- "@nestjs/core": "^10.0.0 || ^11.0.0",
151
+ "@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
152
+ "@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
102
153
  "hono": ">=3.0.0 <5.0.0"
103
154
  },
104
155
  "peerDependenciesMeta": {
@@ -119,13 +170,21 @@
119
170
  "zstd-codec": "^0.1.5"
120
171
  },
121
172
  "devDependencies": {
122
- "@nestjs/common": "^11.0.0",
123
- "@nestjs/core": "^11.0.0",
173
+ "@nestjs/cache-manager": "12.0.5",
174
+ "@nestjs/common": "^12.5.0",
175
+ "@nestjs/core": "^12.5.0",
176
+ "@nestjs/platform-express": "^12.5.0",
124
177
  "@types/node": "^26.6.2",
125
- "hono": "^4.0.0",
178
+ "@opentelemetry/api": "^1.10.0",
179
+ "cache-manager": "7.2.9",
180
+ "hono": "^4.13.16",
181
+ "keyv": "5.6.0",
126
182
  "markdown-it-mathjax3": "^4.3.2",
183
+ "next": "16.4.6",
127
184
  "oxlint": "^1.85.0",
128
185
  "redis": "^6.2.1",
186
+ "reflect-metadata": "^0.2.2",
187
+ "rxjs": "^7.8.2",
129
188
  "tsup": "^8.5.1",
130
189
  "tsx": "^4.23.15",
131
190
  "typescript": "^6.0.3",
@@ -138,7 +197,6 @@
138
197
  },
139
198
  "scripts": {
140
199
  "build": "tsup src/index.ts src/cli.ts src/serialize-worker.ts src/next/index.ts src/nestjs/index.ts src/prisma/index.ts src/drizzle/index.ts src/http/index.ts src/hono/index.ts src/dashboard/index.ts src/edge/index.ts --format esm,cjs --dts --clean",
141
- "postbuild": "node --input-type=module -e \"import{readdirSync,rmSync,statSync}from'fs';import{join}from'path';function clean(d){for(const f of readdirSync(d)){const p=join(d,f);if(statSync(p).isDirectory())clean(p);else if(p.endsWith('.d.cts'))rmSync(p,{force:true});}}clean('dist');\"",
142
200
  "dev": "tsup src/index.ts src/serialize-worker.ts --format esm,cjs --dts --watch",
143
201
  "typecheck": "tsc --noEmit",
144
202
  "typecheck:tests": "tsc --noEmit -p tsconfig.test.json",
@@ -147,6 +205,8 @@
147
205
  "test": "vitest run",
148
206
  "test:integration": "vitest run --config vitest.integration.config.ts",
149
207
  "test:watch": "vitest",
208
+ "check:package": "node scripts/check-package.mjs",
209
+ "check:release-version": "node scripts/check-release-version.mjs",
150
210
  "bench": "node --expose-gc --max-old-space-size=8192 --import tsx/esm bench/benchmark.ts",
151
211
  "bench:roi": "tsx bench/cloud-roi-simulation.ts",
152
212
  "bench:compression": "tsx bench/compression.bench.ts",
@@ -1,4 +1,6 @@
1
1
  import type { IRedisDriver, IRedisPipeline } from '../types';
2
+ import { Cluster } from 'ioredis';
3
+ import { redisHashSlot } from '../utils/redis-slot';
2
4
 
3
5
  export interface AutoPipelinerOptions {
4
6
  /** Maximum number of operations to coalesce before forcing an immediate pipeline dispatch. Default: 100 */
@@ -23,6 +25,15 @@ interface PendingSetexOp {
23
25
  reject: (err: Error) => void;
24
26
  }
25
27
 
28
+ interface PendingSetpxOp {
29
+ type: 'setpx';
30
+ key: string;
31
+ milliseconds: number;
32
+ value: string;
33
+ resolve: () => void;
34
+ reject: (error: Error) => void;
35
+ }
36
+
26
37
  interface PendingDelOp {
27
38
  type: 'del';
28
39
  keys: string[];
@@ -30,7 +41,39 @@ interface PendingDelOp {
30
41
  reject: (err: Error) => void;
31
42
  }
32
43
 
33
- type PendingOp = PendingGetOp | PendingSetexOp | PendingDelOp;
44
+ export interface TimedRedisValue {
45
+ raw: string | Record<string, string> | null;
46
+ ttlMs?: number;
47
+ }
48
+
49
+ interface PendingReadOp {
50
+ type: 'read';
51
+ key: string;
52
+ hash: boolean;
53
+ resolve: (value: TimedRedisValue) => void;
54
+ reject: (err: Error) => void;
55
+ }
56
+
57
+ /** Read value + PTTL in one atomic, single-key transaction where the driver supports it. */
58
+ export async function readRedisValue(client: any, key: string, hash = false): Promise<TimedRedisValue> {
59
+ if (typeof client.pttl === 'function' && typeof client.multi === 'function') {
60
+ const transaction = client.multi();
61
+ if (typeof transaction.pttl === 'function' && (!hash || typeof transaction.hgetall === 'function')) {
62
+ if (hash) transaction.hgetall(key);
63
+ else transaction.get(key);
64
+ transaction.pttl(key);
65
+ const results = await transaction.exec();
66
+ if (!results) throw new Error('Redis read transaction aborted');
67
+ if (results[0]?.[0]) throw results[0][0];
68
+ if (results[1]?.[0]) throw results[1][0];
69
+ return { raw: results[0]?.[1] ?? null, ttlMs: Number(results[1]?.[1]) };
70
+ }
71
+ }
72
+ // Legacy/custom drivers without an atomic TTL read retain the documented L1 fallback TTL.
73
+ return { raw: await (hash ? client.hgetall(key) : client.get(key)) };
74
+ }
75
+
76
+ type PendingOp = PendingGetOp | PendingSetexOp | PendingSetpxOp | PendingDelOp | PendingReadOp;
34
77
 
35
78
  /**
36
79
  * AutoPipeliner — Microtask-coalesced Redis request batching.
@@ -80,6 +123,18 @@ export class AutoPipeliner {
80
123
  });
81
124
  }
82
125
 
126
+ public async read(key: string, hash = false): Promise<TimedRedisValue> {
127
+ if (!hash && typeof this.client.pttl !== 'function') return { raw: await this.get(key) };
128
+ if (!this.enabled || !this.supportsPipelines() || typeof this.client.pttl !== 'function') {
129
+ return readRedisValue(this.client, key, hash);
130
+ }
131
+ const probe = typeof this.client.pipeline === 'function' ? this.client.pipeline() : this.client.multi();
132
+ if (typeof probe.pttl !== 'function' || (hash && typeof probe.hgetall !== 'function')) {
133
+ return readRedisValue(this.client, key, hash);
134
+ }
135
+ return new Promise<TimedRedisValue>((resolve, reject) => this.enqueue({ type: 'read', key, hash, resolve, reject }));
136
+ }
137
+
83
138
  public async setex(key: string, seconds: number, value: string): Promise<void> {
84
139
  if (!this.enabled || !this.supportsPipelines()) {
85
140
  if (typeof this.client.setex === 'function') {
@@ -95,8 +150,19 @@ export class AutoPipeliner {
95
150
  });
96
151
  }
97
152
 
153
+ public async setpx(key: string, milliseconds: number, value: string): Promise<void> {
154
+ if (!this.enabled || !this.supportsPipelines()) {
155
+ await this.client.set(key, value, 'PX', milliseconds);
156
+ return;
157
+ }
158
+ return new Promise<void>((resolve, reject) => this.enqueue({ type: 'setpx', key, milliseconds, value, resolve, reject }));
159
+ }
160
+
98
161
  public async del(...keys: string[]): Promise<number> {
99
162
  if (keys.length === 0) return 0;
163
+ if (this.client instanceof Cluster && keys.length > 1) {
164
+ return (await Promise.all(keys.map(key => this.del(key)))).reduce((sum, value) => sum + value, 0);
165
+ }
100
166
  if (!this.enabled || !this.supportsPipelines()) {
101
167
  return this.client.del(...keys);
102
168
  }
@@ -142,45 +208,58 @@ export class AutoPipeliner {
142
208
  this.statsInternal.batchesDispatched++;
143
209
  this.statsInternal.operationsBatched += batch.length;
144
210
 
145
- const pipe: IRedisPipeline = typeof this.client.pipeline === 'function'
146
- ? this.client.pipeline()
147
- : this.client.multi();
148
-
149
- for (const op of batch) {
150
- switch (op.type) {
151
- case 'get':
152
- pipe.get(op.key);
153
- break;
154
- case 'setex':
155
- pipe.setex(op.key, op.seconds, op.value);
156
- break;
157
- case 'del':
158
- pipe.del(...op.keys);
159
- break;
211
+ if (this.client instanceof Cluster) {
212
+ const groups = new Map<string, PendingOp[]>();
213
+ for (const operation of batch) {
214
+ const key = operation.type === 'del' ? operation.keys[0] : operation.key;
215
+ const slot = redisHashSlot(key);
216
+ const master = this.client.slots[slot]?.[0] ?? String(slot);
217
+ const members = groups.get(master) ?? [];
218
+ members.push(operation);
219
+ groups.set(master, members);
160
220
  }
221
+ await Promise.all([...groups.values()].map(members => this.dispatch(members)));
222
+ return;
161
223
  }
224
+ await this.dispatch(batch);
225
+ }
162
226
 
227
+ private async dispatch(batch: PendingOp[]): Promise<void> {
163
228
  try {
229
+ const pipe: IRedisPipeline = typeof this.client.pipeline === 'function' ? this.client.pipeline() : this.client.multi();
230
+ const indexes: number[] = [];
231
+ let commandCount = 0;
232
+ for (const op of batch) {
233
+ indexes.push(commandCount++);
234
+ switch (op.type) {
235
+ case 'get': pipe.get(op.key); break;
236
+ case 'setex': pipe.setex(op.key, op.seconds, op.value); break;
237
+ case 'setpx': pipe.set(op.key, op.value, 'PX', op.milliseconds); break;
238
+ case 'del': pipe.del(...op.keys); break;
239
+ case 'read':
240
+ if (op.hash) pipe.hgetall!(op.key);
241
+ else pipe.get(op.key);
242
+ pipe.pttl!(op.key);
243
+ commandCount++;
244
+ break;
245
+ }
246
+ }
164
247
  const results = await pipe.exec();
165
248
 
166
249
  if (!results) {
167
250
  // Pipeline returned null / aborted
168
251
  for (const op of batch) {
169
- if (op.type === 'get') op.resolve(null);
170
- else if (op.type === 'del') op.resolve(0);
171
- else op.resolve();
252
+ op.reject(new Error('Redis pipeline aborted'));
172
253
  }
173
254
  return;
174
255
  }
175
256
 
176
257
  for (let i = 0; i < batch.length; i++) {
177
258
  const op = batch[i];
178
- const resTuple = results[i];
259
+ const resTuple = results[indexes[i]];
179
260
 
180
261
  if (!resTuple) {
181
- if (op.type === 'get') op.resolve(null);
182
- else if (op.type === 'del') op.resolve(0);
183
- else op.resolve();
262
+ op.reject(new Error('Missing Redis pipeline result'));
184
263
  continue;
185
264
  }
186
265
 
@@ -188,7 +267,11 @@ export class AutoPipeliner {
188
267
  if (err) {
189
268
  op.reject(err instanceof Error ? err : new Error(String(err)));
190
269
  } else {
191
- if (op.type === 'get') {
270
+ if (op.type === 'read') {
271
+ const ttlResult = results[indexes[i] + 1];
272
+ if (!ttlResult || ttlResult[0]) op.reject(ttlResult?.[0] ?? new Error('Missing Redis PTTL result'));
273
+ else op.resolve({ raw: val, ttlMs: Number(ttlResult[1]) });
274
+ } else if (op.type === 'get') {
192
275
  op.resolve(val != null ? String(val) : null);
193
276
  } else if (op.type === 'del') {
194
277
  op.resolve(typeof val === 'number' ? val : Number(val) || 0);