Merge pull request #838 from judsonjuniorr/v2-fix-cache-errors

Validate if cache exists before accessing it
This commit is contained in:
Davidson Gomes 2024-08-30 09:39:13 -03:00 committed by GitHub
commit 256bd3ef73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,9 @@ export class CacheService {
} }
public async hGet(key: string, field: string) { public async hGet(key: string, field: string) {
if (!this.cache) {
return null;
}
try { try {
const data = await this.cache.hGet(key, field); const data = await this.cache.hGet(key, field);
@ -43,6 +46,9 @@ export class CacheService {
} }
public async hSet(key: string, field: string, value: any) { public async hSet(key: string, field: string, value: any) {
if (!this.cache) {
return;
}
try { try {
const json = JSON.stringify(value, BufferJSON.replacer); const json = JSON.stringify(value, BufferJSON.replacer);
@ -67,6 +73,9 @@ export class CacheService {
} }
async hDelete(key: string, field: string) { async hDelete(key: string, field: string) {
if (!this.cache) {
return false;
}
try { try {
await this.cache.hDelete(key, field); await this.cache.hDelete(key, field);
return true; return true;