change stracture

This commit is contained in:
AmirHossein Mahmoodi
2025-05-10 15:04:19 +03:30
parent 2ce1b136a8
commit ec28b21cf8
8 changed files with 112 additions and 25 deletions

View File

@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { RedisService } from './redis.service';
@Module({
providers: [RedisService],
exports: [RedisService],
})
export class RedisModule {}

View File

@@ -0,0 +1,20 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { createClient } from 'redis';
@Injectable()
export class RedisService implements OnModuleInit {
private client;
async onModuleInit() {
this.client = createClient({
url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`,
});
this.client.on('error', (err) => console.error('Redis Error:', err));
await this.client.connect();
}
getClient() {
return this.client;
}
}