@sqrzro/server 2.0.0-bz.16 → 2.0.0-bz.18
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/cache/CacheService.js +12 -5
- package/package.json +1 -1
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
|
+
let client = null;
|
|
2
3
|
async function getClient() {
|
|
3
|
-
|
|
4
|
+
if (!process.env.REDIS_URL) {
|
|
5
|
+
throw new Error('REDIS_URL is not defined. Access to the cache is not possible.');
|
|
6
|
+
}
|
|
7
|
+
if (client) {
|
|
8
|
+
return client;
|
|
9
|
+
}
|
|
10
|
+
client = createClient({
|
|
11
|
+
url: process.env.REDIS_URL,
|
|
12
|
+
});
|
|
4
13
|
await client.connect();
|
|
5
14
|
return client;
|
|
6
15
|
}
|
|
7
16
|
export async function getFromCache(key) {
|
|
8
|
-
|
|
9
|
-
return client.get(key);
|
|
17
|
+
return (await getClient()).get(key);
|
|
10
18
|
}
|
|
11
19
|
export async function setToCache(key, value) {
|
|
12
|
-
|
|
13
|
-
await client.set(key, value);
|
|
20
|
+
await (await getClient()).set(key, value);
|
|
14
21
|
}
|