@holo-js/cache-redis 0.1.8 → 0.2.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/dist/index.mjs +15 -22
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -183,6 +183,19 @@ function createRedisCacheDriver(options) {
|
|
|
183
183
|
}
|
|
184
184
|
} while (cursor !== "0");
|
|
185
185
|
}
|
|
186
|
+
async function mutateNumericValue(key, amount, mutate) {
|
|
187
|
+
try {
|
|
188
|
+
return await mutate(key, amount);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (!isRedisNumericMutationError(error)) {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
throw new CacheInvalidNumericMutationError(
|
|
194
|
+
`[@holo-js/cache] Cache key "${key}" does not contain a numeric value.`,
|
|
195
|
+
{ cause: error }
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
186
199
|
const driver = {
|
|
187
200
|
name: options.name,
|
|
188
201
|
driver: "redis",
|
|
@@ -227,30 +240,10 @@ function createRedisCacheDriver(options) {
|
|
|
227
240
|
await flushClient(client);
|
|
228
241
|
},
|
|
229
242
|
async increment(key, amount) {
|
|
230
|
-
|
|
231
|
-
return await client.incrby(key, amount);
|
|
232
|
-
} catch (error) {
|
|
233
|
-
if (!isRedisNumericMutationError(error)) {
|
|
234
|
-
throw error;
|
|
235
|
-
}
|
|
236
|
-
throw new CacheInvalidNumericMutationError(
|
|
237
|
-
`[@holo-js/cache] Cache key "${key}" does not contain a numeric value.`,
|
|
238
|
-
{ cause: error }
|
|
239
|
-
);
|
|
240
|
-
}
|
|
243
|
+
return await mutateNumericValue(key, amount, async (targetKey, targetAmount) => await client.incrby(targetKey, targetAmount));
|
|
241
244
|
},
|
|
242
245
|
async decrement(key, amount) {
|
|
243
|
-
|
|
244
|
-
return await client.decrby(key, amount);
|
|
245
|
-
} catch (error) {
|
|
246
|
-
if (!isRedisNumericMutationError(error)) {
|
|
247
|
-
throw error;
|
|
248
|
-
}
|
|
249
|
-
throw new CacheInvalidNumericMutationError(
|
|
250
|
-
`[@holo-js/cache] Cache key "${key}" does not contain a numeric value.`,
|
|
251
|
-
{ cause: error }
|
|
252
|
-
);
|
|
253
|
-
}
|
|
246
|
+
return await mutateNumericValue(key, amount, async (targetKey, targetAmount) => await client.decrby(targetKey, targetAmount));
|
|
254
247
|
},
|
|
255
248
|
lock(name, seconds) {
|
|
256
249
|
return createRedisLock(client, name, seconds, ownerFactory, sleep, now);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/cache-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Holo-JS Framework - Redis cache driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"test:integration": "HOLO_REDIS_INTEGRATION=1 vitest --run"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@holo-js/cache": "^0.
|
|
27
|
+
"@holo-js/cache": "^0.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"ioredis": "^5.4.2",
|
|
31
31
|
"tslib": "^2.8.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@holo-js/cache": "^0.
|
|
34
|
+
"@holo-js/cache": "^0.2.0",
|
|
35
35
|
"@types/node": "^22.10.2",
|
|
36
36
|
"tsup": "^8.3.5",
|
|
37
37
|
"typescript": "^5.7.2",
|