From 7c7025ff14d6027a61be578c3574c8acfee0983c Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 14 Dec 2023 13:58:43 +0300 Subject: [PATCH] feat: change order of adding error handler and connecting functions in redis client --- template/apps/api/src/io-emitter.ts | 4 ++-- template/apps/api/src/services/socket/socket.service.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/template/apps/api/src/io-emitter.ts b/template/apps/api/src/io-emitter.ts index e926e7b7..eaac5a94 100644 --- a/template/apps/api/src/io-emitter.ts +++ b/template/apps/api/src/io-emitter.ts @@ -20,10 +20,10 @@ const publish = (roomId: string | string[], eventName: string, data: unknown) => const initClient = async () => { const subClient = redisClient.duplicate(); - subClient.on('error', redisErrorHandler); - await subClient.connect(); + subClient.on('error', redisErrorHandler); + emitter = new Emitter(subClient); }; diff --git a/template/apps/api/src/services/socket/socket.service.ts b/template/apps/api/src/services/socket/socket.service.ts index d8b09c71..90c7ad9e 100644 --- a/template/apps/api/src/services/socket/socket.service.ts +++ b/template/apps/api/src/services/socket/socket.service.ts @@ -16,11 +16,12 @@ export default async (server: http.Server) => { const subClient = pubClient.duplicate(); - subClient.on('error', redisErrorHandler); - await Promise.all([pubClient.connect(), subClient.connect()]); + logger.info('Socket.io server has been connected.'); + subClient.on('error', redisErrorHandler); + io.adapter(createAdapter(pubClient, subClient)); io.use(async (socket, next) => {