@@ -5,11 +5,10 @@ import { Db } from 'mongodb';
55import { Collection } from 'mongoose' ;
66import { join } from 'path' ;
77
8- import { Auth , ConfigService , Database , DelInstance , HttpServer , Redis } from '../../config/env.config' ;
8+ import { Auth , CacheConf , ConfigService , Database , DelInstance , HttpServer } from '../../config/env.config' ;
99import { Logger } from '../../config/logger.config' ;
1010import { INSTANCE_DIR , STORE_DIR } from '../../config/path.config' ;
1111import { NotFoundException } from '../../exceptions' ;
12- import { RedisCache } from '../../libs/redis.client' ;
1312import {
1413 AuthModel ,
1514 ChamaaiModel ,
@@ -34,7 +33,7 @@ export class WAMonitoringService {
3433 private readonly eventEmitter : EventEmitter2 ,
3534 private readonly configService : ConfigService ,
3635 private readonly repository : RepositoryBroker ,
37- private readonly cache : RedisCache ,
36+ private readonly cache : CacheService ,
3837 private readonly chatwootCache : CacheService ,
3938 private readonly messagesLostCache : CacheService ,
4039 ) {
@@ -44,15 +43,15 @@ export class WAMonitoringService {
4443 this . noConnection ( ) ;
4544
4645 Object . assign ( this . db , configService . get < Database > ( 'DATABASE' ) ) ;
47- Object . assign ( this . redis , configService . get < Redis > ( 'REDIS ' ) ) ;
46+ Object . assign ( this . redis , configService . get < CacheConf > ( 'CACHE ' ) ) ;
4847
4948 this . dbInstance = this . db . ENABLED
5049 ? this . repository . dbServer ?. db ( this . db . CONNECTION . DB_PREFIX_NAME + '-instances' )
5150 : undefined ;
5251 }
5352
5453 private readonly db : Partial < Database > = { } ;
55- private readonly redis : Partial < Redis > = { } ;
54+ private readonly redis : Partial < CacheConf > = { } ;
5655
5756 private dbInstance : Db ;
5857
@@ -213,7 +212,7 @@ export class WAMonitoringService {
213212 } ) ;
214213 this . logger . verbose ( 'instance files deleted: ' + name ) ;
215214 } ) ;
216- } else if ( ! this . redis . ENABLED ) {
215+ } else if ( ! this . redis . REDIS . ENABLED && ! this . redis . REDIS . SAVE_INSTANCES ) {
217216 const dir = opendirSync ( INSTANCE_DIR , { encoding : 'utf-8' } ) ;
218217 for await ( const dirent of dir ) {
219218 if ( dirent . isDirectory ( ) ) {
@@ -248,10 +247,9 @@ export class WAMonitoringService {
248247 return ;
249248 }
250249
251- if ( this . redis . ENABLED ) {
250+ if ( this . redis . REDIS . ENABLED && this . redis . REDIS . SAVE_INSTANCES ) {
252251 this . logger . verbose ( 'cleaning up instance in redis: ' + instanceName ) ;
253- this . cache . reference = instanceName ;
254- await this . cache . delAll ( ) ;
252+ await this . cache . delete ( instanceName ) ;
255253 return ;
256254 }
257255
@@ -304,7 +302,7 @@ export class WAMonitoringService {
304302 this . logger . verbose ( 'Loading instances' ) ;
305303
306304 try {
307- if ( this . redis . ENABLED ) {
305+ if ( this . redis . REDIS . ENABLED && this . redis . REDIS . SAVE_INSTANCES ) {
308306 await this . loadInstancesFromRedis ( ) ;
309307 } else if ( this . db . ENABLED && this . db . SAVE_DATA . INSTANCE ) {
310308 await this . loadInstancesFromDatabase ( ) ;
@@ -377,12 +375,11 @@ export class WAMonitoringService {
377375
378376 private async loadInstancesFromRedis ( ) {
379377 this . logger . verbose ( 'Redis enabled' ) ;
380- await this . cache . connect ( this . redis as Redis ) ;
381- const keys = await this . cache . getInstanceKeys ( ) ;
378+ const keys = await this . cache . keys ( ) ;
382379
383380 if ( keys ?. length > 0 ) {
384381 this . logger . verbose ( 'Reading instance keys and setting instances' ) ;
385- await Promise . all ( keys . map ( ( k ) => this . setInstance ( k . split ( ':' ) [ 1 ] ) ) ) ;
382+ await Promise . all ( keys . map ( ( k ) => this . setInstance ( k . split ( ':' ) [ 2 ] ) ) ) ;
386383 } else {
387384 this . logger . verbose ( 'No instance keys found' ) ;
388385 }
0 commit comments