From 625447e7f17fe98692155c42b6ce8e94121c8fb2 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 14 Aug 2023 22:15:19 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=8A=20Added=20shared=20Redis=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/redis.config.ts | 10 ++++++++++ services/socket.service.ts | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 config/redis.config.ts diff --git a/config/redis.config.ts b/config/redis.config.ts new file mode 100644 index 0000000..3d6cf0b --- /dev/null +++ b/config/redis.config.ts @@ -0,0 +1,10 @@ +import { createClient } from "redis"; +const redisURL = new URL(process.env.REDIS_URI); + +const pubClient = createClient({ url: `redis://${redisURL.hostname}:6379` }); +(async () => { + await pubClient.connect(); +})(); +const subClient = pubClient.duplicate(); + +export { subClient, pubClient }; diff --git a/services/socket.service.ts b/services/socket.service.ts index 40add1c..eedd2f5 100644 --- a/services/socket.service.ts +++ b/services/socket.service.ts @@ -3,14 +3,9 @@ import { Service, ServiceBroker, ServiceSchema, Context } from "moleculer"; import { createClient } from "redis"; import { createAdapter } from "@socket.io/redis-adapter"; import Session from "../models/session.model"; +import { pubClient, subClient } from "../config/redis.config"; const SocketIOService = require("moleculer-io"); const { v4: uuidv4 } = require("uuid"); -const redisURL = new URL(process.env.REDIS_URI); -const pubClient = createClient({ url: `redis://${redisURL.hostname}:6379` }); -(async () => { - await pubClient.connect(); -})(); -const subClient = pubClient.duplicate(); export default class SocketService extends Service { // @ts-ignore