'missing 'error' handler on this Redis client
It's really an odd issue I cannot detect, here's my adapter.
import { IoAdapter } from '@nestjs/platform-socket.io';
import { ServerOptions } from 'socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import { createClient } from 'redis';
import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { IAppConfig, IRedisConfig } from '@app/app-config';
export class RedisIoAdapter extends IoAdapter {
private adapterConstructor: ReturnType<typeof createAdapter>;
constructor(app: INestApplication, private configService: ConfigService<IAppConfig>) {
super(app);
}
async connectToRedis(): Promise<void> {
const redisConfig = this.configService.get<IRedisConfig>('redis');
if (redisConfig) {
const { host, port } = redisConfig;
const pubClient = createClient({ url: `redis://${host}:${port}` });
const subClient = pubClient.duplicate();
await Promise.all([pubClient.connect(), subClient.connect()]);
this.adapterConstructor = createAdapter(pubClient, subClient);
}
}
createIOServer(port: number, options?: ServerOptions): any {
const server = super.createIOServer(port, options);
server.adapter(this.adapterConstructor);
return server;
}
}
Solution 1:[1]
Here error handler not added to the code.
pubClient.on("error", (err) => {
console.log(err.message);
});
subClient.on("error", (err) => {
console.log(err.message);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Pramod Kumar |