From b452029411c0924e5e1de3a194ce8c23eb489258 Mon Sep 17 00:00:00 2001 From: Alexandre Paixao Date: Mon, 1 Sep 2025 16:37:15 +0200 Subject: [PATCH 1/2] Don't duplicate "specificResponseChannel" naming logic --- lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index 57a0f62..de67af3 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -479,7 +479,7 @@ export class RedisAdapter extends Adapter { */ private publishResponse(request, response) { const responseChannel = this.publishOnSpecificResponseChannel - ? `${this.responseChannel}${request.uid}#` + ? this.specificResponseChannel : this.responseChannel; debug("publishing response to channel %s", responseChannel); this.pubClient.publish(responseChannel, response); From da003df18c0624ed8c2f70dab669c4b8341ad57c Mon Sep 17 00:00:00 2001 From: Alexandre Paixao Date: Mon, 1 Sep 2025 16:45:47 +0200 Subject: [PATCH 2/2] Don't create specific response channel if not needed --- lib/index.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index de67af3..748b538 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -97,13 +97,11 @@ export function createAdapter( export class RedisAdapter extends Adapter { public readonly uid; public readonly requestsTimeout: number; - public readonly publishOnSpecificResponseChannel: boolean; public readonly parser: Parser; private readonly channel: string; private readonly requestChannel: string; private readonly responseChannel: string; - private readonly specificResponseChannel: string; private requests: Map = new Map(); private ackRequests: Map = new Map(); private redisListeners: Map = new Map(); @@ -129,8 +127,6 @@ export class RedisAdapter extends Adapter { this.uid = uid2(6); this.requestsTimeout = opts.requestsTimeout || 5000; - this.publishOnSpecificResponseChannel = - !!opts.publishOnSpecificResponseChannel; this.parser = opts.parser || msgpack; const prefix = opts.key || "socket.io"; @@ -138,7 +134,9 @@ export class RedisAdapter extends Adapter { this.channel = prefix + "#" + nsp.name + "#"; this.requestChannel = prefix + "-request#" + this.nsp.name + "#"; this.responseChannel = prefix + "-response#" + this.nsp.name + "#"; - this.specificResponseChannel = this.responseChannel + this.uid + "#"; + if (opts.publishOnSpecificResponseChannel) { + this.responseChannel = this.responseChannel + this.uid + "#"; + } const isRedisV4 = typeof this.pubClient.pSubscribe === "function"; if (isRedisV4) { @@ -159,7 +157,6 @@ export class RedisAdapter extends Adapter { [ this.requestChannel, this.responseChannel, - this.specificResponseChannel, ], this.redisListeners.get("sub"), true @@ -177,7 +174,6 @@ export class RedisAdapter extends Adapter { this.subClient.subscribe([ this.requestChannel, this.responseChannel, - this.specificResponseChannel, ]); this.subClient.on( "messageBuffer", @@ -478,11 +474,8 @@ export class RedisAdapter extends Adapter { * @private */ private publishResponse(request, response) { - const responseChannel = this.publishOnSpecificResponseChannel - ? this.specificResponseChannel - : this.responseChannel; - debug("publishing response to channel %s", responseChannel); - this.pubClient.publish(responseChannel, response); + debug("publishing response to channel %s", this.responseChannel); + this.pubClient.publish(this.responseChannel, response); } /** @@ -915,11 +908,6 @@ export class RedisAdapter extends Adapter { this.redisListeners.get("sub"), true ); - this.subClient.unsubscribe( - this.specificResponseChannel, - this.redisListeners.get("sub"), - true - ); } else { this.subClient.punsubscribe(this.channel + "*"); this.subClient.off( @@ -927,11 +915,6 @@ export class RedisAdapter extends Adapter { this.redisListeners.get("pmessageBuffer") ); - this.subClient.unsubscribe([ - this.requestChannel, - this.responseChannel, - this.specificResponseChannel, - ]); this.subClient.off( "messageBuffer", this.redisListeners.get("messageBuffer")