Skip to content

Commit a19343d

Browse files
committed
Validate if cache exists before accessing it
1 parent 3b97619 commit a19343d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/api/services/cache.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class CacheService {
2121
}
2222

2323
public async hGet(key: string, field: string) {
24+
if (!this.cache) {
25+
return null;
26+
}
2427
try {
2528
const data = await this.cache.hGet(key, field);
2629

@@ -43,6 +46,9 @@ export class CacheService {
4346
}
4447

4548
public async hSet(key: string, field: string, value: any) {
49+
if (!this.cache) {
50+
return;
51+
}
4652
try {
4753
const json = JSON.stringify(value, BufferJSON.replacer);
4854

@@ -67,6 +73,9 @@ export class CacheService {
6773
}
6874

6975
async hDelete(key: string, field: string) {
76+
if (!this.cache) {
77+
return false;
78+
}
7079
try {
7180
await this.cache.hDelete(key, field);
7281
return true;

0 commit comments

Comments
 (0)