mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-22 21:32:21 -06:00
fix: Adjusts in redis for save instances
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { BufferJSON } from '@whiskeysockets/baileys';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ICache } from '../abstract/abstract.cache';
|
||||
|
||||
@@ -20,6 +22,21 @@ export class CacheService {
|
||||
return this.cache.get(key);
|
||||
}
|
||||
|
||||
public async hGet(key: string, field: string) {
|
||||
try {
|
||||
const data = await this.cache.hGet(key, field);
|
||||
|
||||
if (data) {
|
||||
return JSON.parse(data, BufferJSON.reviver);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async set(key: string, value: any) {
|
||||
if (!this.cache) {
|
||||
return;
|
||||
@@ -28,6 +45,16 @@ export class CacheService {
|
||||
this.cache.set(key, value);
|
||||
}
|
||||
|
||||
public async hSet(key: string, field: string, value: any) {
|
||||
try {
|
||||
const json = JSON.stringify(value, BufferJSON.replacer);
|
||||
|
||||
await this.cache.hSet(key, field, json);
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async has(key: string) {
|
||||
if (!this.cache) {
|
||||
return;
|
||||
@@ -44,6 +71,16 @@ export class CacheService {
|
||||
return this.cache.delete(key);
|
||||
}
|
||||
|
||||
async hDelete(key: string, field: string) {
|
||||
try {
|
||||
await this.cache.hDelete(key, field);
|
||||
return true;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteAll(appendCriteria?: string) {
|
||||
if (!this.cache) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user