Skip to content

Commit

Permalink
🐛💥 reconfiguration of the code that saves the instances in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Dec 9, 2023
1 parent a2474ed commit 0b16a32
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 250 deletions.
52 changes: 52 additions & 0 deletions src/cache/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { RedisClientType, createClient } from 'redis';
import { ConfigService, Redis } from '../config/env.config';
import { Logger } from '../config/logger.config';

export class RedisCache {
constructor(private readonly configService: ConfigService) {}

private readonly logger = new Logger(this.configService, RedisCache.name);

private _client: RedisClientType;

public get client() {
return this._client;
}

public get isConnected() {
return this.client?.isOpen;
}

private readonly config = Object.freeze(this.configService.get<Redis>('REDIS'));

public async onModuleInit() {
if (this.config.ENABLED) {
this._client = createClient({
url: this.config.URI,
name: 'codechat_v1',
});
await this.client.connect();
this.logger.info('Redis:Connected - ON');
}
}

public async onModuleDestroy() {
await this.client.disconnect();
this.logger.warn('Cache:Redis - OFF');
}

public keys(pattern: string) {
return new Promise<string[]>((resolve, reject) => {
resolve(this.client.keys(pattern));
reject(new Error('Error on get keys'));
});
}

public async del(key: string) {
try {
return await this.client.del(`${this.config.PREFIX_KEY}:${key}`);
} catch (error) {
this.logger.error({ localError: 'dell', error });
}
}
}
62 changes: 0 additions & 62 deletions src/utils/server-up.ts

This file was deleted.

125 changes: 0 additions & 125 deletions src/utils/use-multi-file-auth-state-db.ts

This file was deleted.

Loading

0 comments on commit 0b16a32

Please sign in to comment.