Skip to content

Commit 0851456

Browse files
author
matus.hudec
committed
Release 7.0.4-beta
1 parent 5608e07 commit 0851456

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/httpClient/redisStorage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ export default async function createRedisStorage(redisEndpoint: string) {
1010
const redis = require('redis');
1111

1212
const client = redis.createClient({ url: redisEndpoint });
13-
await client.connect();
1413

1514
// source https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage
1615
return buildStorage({
1716
async find(key) {
17+
if (!client.isReady) await client.connect();
1818
const result = await client.get(`${KEY_PREFIX}${key}`);
1919
return result ? (JSON.parse(result) as StorageValue) : undefined;
2020
},
2121

2222
// eslint-disable-next-line complexity
2323
async set(key, value, req) {
24+
if (!client.isReady) await client.connect();
2425
await client.set(`${KEY_PREFIX}${key}`, JSON.stringify(value), {
2526
PXAT:
2627
// We don't want to keep indefinitely values in the storage if
@@ -39,6 +40,7 @@ export default async function createRedisStorage(redisEndpoint: string) {
3940
},
4041

4142
async remove(key) {
43+
if (!client.isReady) await client.connect();
4244
await client.del(`${KEY_PREFIX}${key}`);
4345
},
4446
});

0 commit comments

Comments
 (0)