@zauru-sdk/services 2.0.191 → 2.0.192
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/esm/index.js +1 -0
- package/dist/esm/redis/redisQueue.js +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/redis/redisQueue.d.ts +2 -0
- package/package.json +3 -2
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Redis } from "@upstash/redis";
|
|
2
|
+
import { config } from "@zauru-sdk/config";
|
|
3
|
+
const redis = new Redis({
|
|
4
|
+
url: config.redisBaseURL,
|
|
5
|
+
token: config.redisToken,
|
|
6
|
+
});
|
|
7
|
+
// Función para intentar adquirir el lock
|
|
8
|
+
export async function acquireLock(key, lockValue, expiration) {
|
|
9
|
+
// Usamos SET con NX (solo si no existe) y PX para expirar el lock en milisegundos
|
|
10
|
+
const result = await redis.set(key, lockValue, {
|
|
11
|
+
nx: true,
|
|
12
|
+
pxat: Date.now() + expiration,
|
|
13
|
+
});
|
|
14
|
+
return result === "OK";
|
|
15
|
+
}
|
|
16
|
+
// Función para liberar el lock de forma segura usando un script Lua
|
|
17
|
+
export async function releaseLock(key, lockValue) {
|
|
18
|
+
const script = `
|
|
19
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
20
|
+
return redis.call("del", KEYS[1])
|
|
21
|
+
else
|
|
22
|
+
return 0
|
|
23
|
+
end
|
|
24
|
+
`;
|
|
25
|
+
await redis.eval(script, [key], [lockValue]);
|
|
26
|
+
}
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.192",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
|
+
"@upstash/redis": "^1.34.5",
|
|
27
28
|
"@zauru-sdk/common": "^2.0.187",
|
|
28
29
|
"@zauru-sdk/config": "^2.0.100",
|
|
29
30
|
"@zauru-sdk/graphql": "^2.0.187",
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
"axios": "^1.6.7",
|
|
32
33
|
"chalk": "5.3.0"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "f6269687436623477fdcb6e69011ee9560fcd905"
|
|
35
36
|
}
|