@holo-js/cache-redis 0.1.4 → 0.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/dist/index.d.ts CHANGED
@@ -71,6 +71,7 @@ type RedisClusterOptions = {
71
71
  };
72
72
  type RedisClientLike = {
73
73
  readonly isCluster?: boolean;
74
+ disconnect?(): void;
74
75
  get(key: string): Promise<string | null>;
75
76
  set(key: string, value: string, ...arguments_: readonly (string | number)[]): Promise<'OK' | null>;
76
77
  del(...keys: string[]): Promise<number>;
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  CacheInvalidNumericMutationError
6
6
  } from "@holo-js/cache";
7
7
  var REDIS_SCAN_COUNT = 100;
8
+ var CACHE_DRIVER_DISPOSE_SYMBOL = /* @__PURE__ */ Symbol.for("holo.cache.driver.dispose");
8
9
  var RELEASE_LOCK_SCRIPT = [
9
10
  'if redis.call("get", KEYS[1]) == ARGV[1] then',
10
11
  ' return redis.call("del", KEYS[1])',
@@ -153,10 +154,14 @@ function createRedisLock(client, name, seconds, ownerFactory, sleep, now) {
153
154
  if (await tryAcquire()) {
154
155
  return withCallback(callback);
155
156
  }
157
+ const remainingWait = deadline - now();
158
+ if (remainingWait <= 0) {
159
+ return false;
160
+ }
161
+ await sleep(Math.min(10, remainingWait));
156
162
  if (now() >= deadline) {
157
163
  return false;
158
164
  }
159
- await sleep(10);
160
165
  }
161
166
  }
162
167
  };
@@ -178,7 +183,7 @@ function createRedisCacheDriver(options) {
178
183
  }
179
184
  } while (cursor !== "0");
180
185
  }
181
- return {
186
+ const driver = {
182
187
  name: options.name,
183
188
  driver: "redis",
184
189
  async get(key) {
@@ -204,10 +209,6 @@ function createRedisCacheDriver(options) {
204
209
  return true;
205
210
  },
206
211
  async add(input) {
207
- if (typeof input.expiresAt === "number" && input.expiresAt <= now()) {
208
- await client.del(input.key);
209
- return true;
210
- }
211
212
  if (typeof input.expiresAt === "number") {
212
213
  return await client.set(input.key, input.payload, "PXAT", input.expiresAt, "NX") === "OK";
213
214
  }
@@ -255,6 +256,12 @@ function createRedisCacheDriver(options) {
255
256
  return createRedisLock(client, name, seconds, ownerFactory, sleep, now);
256
257
  }
257
258
  };
259
+ Object.defineProperty(driver, CACHE_DRIVER_DISPOSE_SYMBOL, {
260
+ value() {
261
+ client.disconnect?.();
262
+ }
263
+ });
264
+ return driver;
258
265
  }
259
266
  var redisCacheDriverInternals = {
260
267
  createRedisClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/cache-redis",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Holo-JS Framework - Redis cache driver",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,20 +20,21 @@
20
20
  "build": "tsup",
21
21
  "stub": "tsup",
22
22
  "typecheck": "tsc -p tsconfig.json --noEmit",
23
- "test": "vitest --run"
23
+ "test": "vitest --run",
24
+ "test:integration": "HOLO_REDIS_INTEGRATION=1 vitest --run"
24
25
  },
25
26
  "peerDependencies": {
26
- "@holo-js/cache": "^0.1.4"
27
+ "@holo-js/cache": "^0.1.6"
27
28
  },
28
29
  "dependencies": {
29
- "ioredis": "catalog:",
30
+ "ioredis": "^5.4.2",
30
31
  "tslib": "^2.8.1"
31
32
  },
32
33
  "devDependencies": {
33
- "@holo-js/cache": "workspace:*",
34
+ "@holo-js/cache": "^0.1.6",
34
35
  "@types/node": "^22.10.2",
35
36
  "tsup": "^8.3.5",
36
37
  "typescript": "^5.7.2",
37
- "vitest": "^2.1.8"
38
+ "vitest": "^4.1.5"
38
39
  }
39
40
  }