|
1 | 1 | import uid2 = require("uid2"); |
2 | 2 | import msgpack = require("notepack.io"); |
3 | 3 | import { Adapter, BroadcastOptions, Room } from "socket.io-adapter"; |
4 | | -import { parseNumSubResponse, sumValues } from "./util"; |
| 4 | +import { PUBSUB } from "./util"; |
5 | 5 |
|
6 | 6 | const debug = require("debug")("socket.io-redis"); |
7 | 7 |
|
@@ -891,49 +891,7 @@ export class RedisAdapter extends Adapter { |
891 | 891 | } |
892 | 892 |
|
893 | 893 | override serverCount(): Promise<number> { |
894 | | - if ( |
895 | | - this.pubClient.constructor.name === "Cluster" || |
896 | | - this.pubClient.isCluster |
897 | | - ) { |
898 | | - // ioredis cluster |
899 | | - const nodes = this.pubClient.nodes(); |
900 | | - return Promise.all( |
901 | | - nodes.map((node) => |
902 | | - node |
903 | | - .send_command("pubsub", ["numsub", this.requestChannel]) |
904 | | - .then(parseNumSubResponse) |
905 | | - ) |
906 | | - ).then(sumValues); |
907 | | - } else if (typeof this.pubClient.pSubscribe === "function") { |
908 | | - // node-redis client |
909 | | - const isCluster = Array.isArray(this.pubClient.masters); |
910 | | - if (isCluster) { |
911 | | - const nodes = this.pubClient.masters; |
912 | | - return Promise.all( |
913 | | - nodes.map((node) => { |
914 | | - return node.client |
915 | | - .sendCommand(["pubsub", "numsub", this.requestChannel]) |
916 | | - .then(parseNumSubResponse); |
917 | | - }) |
918 | | - ).then(sumValues); |
919 | | - } else { |
920 | | - return this.pubClient |
921 | | - .sendCommand(["pubsub", "numsub", this.requestChannel]) |
922 | | - .then(parseNumSubResponse); |
923 | | - } |
924 | | - } else { |
925 | | - // ioredis or node-redis v3 client |
926 | | - return new Promise((resolve, reject) => { |
927 | | - this.pubClient.send_command( |
928 | | - "pubsub", |
929 | | - ["numsub", this.requestChannel], |
930 | | - (err, numSub) => { |
931 | | - if (err) return reject(err); |
932 | | - resolve(parseNumSubResponse(numSub)); |
933 | | - } |
934 | | - ); |
935 | | - }); |
936 | | - } |
| 894 | + return PUBSUB(this.pubClient, "NUMSUB", this.requestChannel); |
937 | 895 | } |
938 | 896 |
|
939 | 897 | close(): Promise<void> | void { |
|
0 commit comments