1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 05:46:46 +01:00
immich/server/src/infra/redis-io.adapter.ts

24 lines
877 B
TypeScript
Raw Normal View History

2023-03-31 16:36:08 +02:00
import { IoAdapter } from '@nestjs/platform-socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import Redis from 'ioredis';
import { Logger } from '@nestjs/common';
2023-03-31 16:36:08 +02:00
import { ServerOptions } from 'socket.io';
import { redisConfig } from './infra.config';
export class RedisIoAdapter extends IoAdapter {
private readonly logger = new Logger(RedisIoAdapter.name);
2023-03-31 16:36:08 +02:00
createIOServer(port: number, options?: ServerOptions): any {
const pubClient = new Redis(redisConfig);
pubClient.on('error', (error) => {
this.logger.error(`Redis pubClient: ${error}`);
});
2023-03-31 16:36:08 +02:00
const subClient = pubClient.duplicate();
subClient.on('error', (error) => {
this.logger.error(`Redis subClient: ${error}`);
});
2023-03-31 16:36:08 +02:00
const server = super.createIOServer(port, options);
server.adapter(createAdapter(pubClient, subClient));
return server;
}
}