@@ -203,6 +203,10 @@ export class RedisAdapter extends Adapter {
203203
204204 switch ( request . type ) {
205205 case RequestType . SOCKETS :
206+ if ( this . requests . has ( request . requestId ) ) {
207+ return ;
208+ }
209+
206210 const sockets = await super . sockets ( new Set ( request . rooms ) ) ;
207211
208212 response = JSON . stringify ( {
@@ -214,6 +218,10 @@ export class RedisAdapter extends Adapter {
214218 break ;
215219
216220 case RequestType . ALL_ROOMS :
221+ if ( this . requests . has ( request . requestId ) ) {
222+ return ;
223+ }
224+
217225 response = JSON . stringify ( {
218226 requestId : request . requestId ,
219227 rooms : [ ...this . rooms . keys ( ) ] ,
@@ -437,11 +445,15 @@ export class RedisAdapter extends Adapter {
437445 * @param {Set<Room> } rooms the explicit set of rooms to check.
438446 */
439447 public async sockets ( rooms : Set < Room > ) : Promise < Set < SocketId > > {
440- const requestId = uid2 ( 6 ) ;
441-
448+ const localSockets = await super . sockets ( rooms ) ;
442449 const numSub = await this . getNumSub ( ) ;
443450 debug ( 'waiting for %d responses to "sockets" request' , numSub ) ;
444451
452+ if ( numSub <= 1 ) {
453+ return Promise . resolve ( localSockets ) ;
454+ }
455+
456+ const requestId = uid2 ( 6 ) ;
445457 const request = JSON . stringify ( {
446458 requestId,
447459 type : RequestType . SOCKETS ,
@@ -463,8 +475,8 @@ export class RedisAdapter extends Adapter {
463475 numSub,
464476 resolve,
465477 timeout,
466- msgCount : 0 ,
467- sockets : new Set ( ) ,
478+ msgCount : 1 ,
479+ sockets : localSockets ,
468480 } ) ;
469481
470482 this . pubClient . publish ( this . requestChannel , request ) ;
@@ -477,11 +489,15 @@ export class RedisAdapter extends Adapter {
477489 * @public
478490 */
479491 public async allRooms ( ) : Promise < Set < Room > > {
480- const requestId = uid2 ( 6 ) ;
481-
492+ const localRooms = new Set ( this . rooms . keys ( ) ) ;
482493 const numSub = await this . getNumSub ( ) ;
483494 debug ( 'waiting for %d responses to "allRooms" request' , numSub ) ;
484495
496+ if ( numSub <= 1 ) {
497+ return localRooms ;
498+ }
499+
500+ const requestId = uid2 ( 6 ) ;
485501 const request = JSON . stringify ( {
486502 requestId,
487503 type : RequestType . ALL_ROOMS ,
@@ -502,8 +518,8 @@ export class RedisAdapter extends Adapter {
502518 numSub,
503519 resolve,
504520 timeout,
505- msgCount : 0 ,
506- rooms : new Set ( ) ,
521+ msgCount : 1 ,
522+ rooms : localRooms ,
507523 } ) ;
508524
509525 this . pubClient . publish ( this . requestChannel , request ) ;
0 commit comments