refactor(server): redis config (#13538)

* refactor(server): redis config

* refactor: cache parsed env data

* chore: add database and redis tests
This commit is contained in:
Jason Rasmussen 2024-10-17 10:50:54 -04:00 committed by GitHub
parent 79acbc1d7b
commit 3f663106e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 318 additions and 173 deletions

View file

@ -3,7 +3,7 @@ import { IoAdapter } from '@nestjs/platform-socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import { Redis } from 'ioredis';
import { ServerOptions } from 'socket.io';
import { parseRedisConfig } from 'src/config';
import { IConfigRepository } from 'src/interfaces/config.interface';
export class WebSocketAdapter extends IoAdapter {
constructor(private app: INestApplicationContext) {
@ -11,8 +11,9 @@ export class WebSocketAdapter extends IoAdapter {
}
createIOServer(port: number, options?: ServerOptions): any {
const { redis } = this.app.get<IConfigRepository>(IConfigRepository).getEnv();
const server = super.createIOServer(port, options);
const pubClient = new Redis(parseRedisConfig());
const pubClient = new Redis(redis);
const subClient = pubClient.duplicate();
server.adapter(createAdapter(pubClient, subClient));
return server;