File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -900,7 +900,7 @@ export class RedisAdapter extends Adapter {
900
900
this . pubClient . constructor . name === "Cluster" ||
901
901
this . pubClient . isCluster
902
902
) {
903
- // Cluster
903
+ // ioredis cluster
904
904
const nodes = this . pubClient . nodes ( ) ;
905
905
return Promise . all (
906
906
nodes . map ( ( node ) =>
@@ -914,11 +914,32 @@ export class RedisAdapter extends Adapter {
914
914
return numSub ;
915
915
} ) ;
916
916
} else if ( typeof this . pubClient . pSubscribe === "function" ) {
917
- return this . pubClient
918
- . sendCommand ( [ "pubsub" , "numsub" , this . requestChannel ] )
919
- . then ( ( res ) => parseInt ( res [ 1 ] , 10 ) ) ;
917
+ // node-redis client
918
+ const isCluster = Array . isArray ( this . pubClient . masters ) ;
919
+ if ( isCluster ) {
920
+ const nodes = this . pubClient . masters ;
921
+ return Promise . all (
922
+ nodes . map ( ( node ) => {
923
+ return node . client . sendCommand ( [
924
+ "pubsub" ,
925
+ "numsub" ,
926
+ this . requestChannel ,
927
+ ] ) ;
928
+ } )
929
+ ) . then ( ( values ) => {
930
+ let numSub = 0 ;
931
+ values . map ( ( value ) => {
932
+ numSub += parseInt ( value [ 1 ] , 10 ) ;
933
+ } ) ;
934
+ return numSub ;
935
+ } ) ;
936
+ } else {
937
+ return this . pubClient
938
+ . sendCommand ( [ "pubsub" , "numsub" , this . requestChannel ] )
939
+ . then ( ( res ) => parseInt ( res [ 1 ] , 10 ) ) ;
940
+ }
920
941
} else {
921
- // RedisClient or Redis
942
+ // ioredis or node-redis v3 client
922
943
return new Promise ( ( resolve , reject ) => {
923
944
this . pubClient . send_command (
924
945
"pubsub" ,
You can’t perform that action at this time.
0 commit comments