cluster-slots.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. "use strict";
  2. var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
  3. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
  4. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  5. return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
  6. };
  7. var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
  8. if (kind === "m") throw new TypeError("Private method is not writable");
  9. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
  10. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  11. return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
  12. };
  13. var _RedisClusterSlots_instances, _a, _RedisClusterSlots_SLOTS, _RedisClusterSlots_options, _RedisClusterSlots_Client, _RedisClusterSlots_emit, _RedisClusterSlots_isOpen, _RedisClusterSlots_discoverWithRootNodes, _RedisClusterSlots_resetSlots, _RedisClusterSlots_discover, _RedisClusterSlots_getShards, _RedisClusterSlots_getNodeAddress, _RedisClusterSlots_clientOptionsDefaults, _RedisClusterSlots_initiateSlotNode, _RedisClusterSlots_createClient, _RedisClusterSlots_createNodeClient, _RedisClusterSlots_runningRediscoverPromise, _RedisClusterSlots_rediscover, _RedisClusterSlots_destroy, _RedisClusterSlots_execOnNodeClient, _RedisClusterSlots_iterateAllNodes, _RedisClusterSlots_randomNodeIterator, _RedisClusterSlots_slotNodesIterator, _RedisClusterSlots_initiatePubSubClient, _RedisClusterSlots_initiateShardedPubSubClient;
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. const client_1 = require("../client");
  16. const errors_1 = require("../errors");
  17. const util_1 = require("util");
  18. const pub_sub_1 = require("../client/pub-sub");
  19. // We need to use 'require', because it's not possible with Typescript to import
  20. // function that are exported as 'module.exports = function`, without esModuleInterop
  21. // set to true.
  22. const calculateSlot = require('cluster-key-slot');
  23. class RedisClusterSlots {
  24. get isOpen() {
  25. return __classPrivateFieldGet(this, _RedisClusterSlots_isOpen, "f");
  26. }
  27. constructor(options, emit) {
  28. _RedisClusterSlots_instances.add(this);
  29. _RedisClusterSlots_options.set(this, void 0);
  30. _RedisClusterSlots_Client.set(this, void 0);
  31. _RedisClusterSlots_emit.set(this, void 0);
  32. Object.defineProperty(this, "slots", {
  33. enumerable: true,
  34. configurable: true,
  35. writable: true,
  36. value: new Array(__classPrivateFieldGet(_a, _a, "f", _RedisClusterSlots_SLOTS))
  37. });
  38. Object.defineProperty(this, "shards", {
  39. enumerable: true,
  40. configurable: true,
  41. writable: true,
  42. value: new Array()
  43. });
  44. Object.defineProperty(this, "masters", {
  45. enumerable: true,
  46. configurable: true,
  47. writable: true,
  48. value: new Array()
  49. });
  50. Object.defineProperty(this, "replicas", {
  51. enumerable: true,
  52. configurable: true,
  53. writable: true,
  54. value: new Array()
  55. });
  56. Object.defineProperty(this, "nodeByAddress", {
  57. enumerable: true,
  58. configurable: true,
  59. writable: true,
  60. value: new Map()
  61. });
  62. Object.defineProperty(this, "pubSubNode", {
  63. enumerable: true,
  64. configurable: true,
  65. writable: true,
  66. value: void 0
  67. });
  68. _RedisClusterSlots_isOpen.set(this, false);
  69. _RedisClusterSlots_runningRediscoverPromise.set(this, void 0);
  70. _RedisClusterSlots_randomNodeIterator.set(this, void 0);
  71. __classPrivateFieldSet(this, _RedisClusterSlots_options, options, "f");
  72. __classPrivateFieldSet(this, _RedisClusterSlots_Client, client_1.default.extend(options), "f");
  73. __classPrivateFieldSet(this, _RedisClusterSlots_emit, emit, "f");
  74. }
  75. async connect() {
  76. if (__classPrivateFieldGet(this, _RedisClusterSlots_isOpen, "f")) {
  77. throw new Error('Cluster already open');
  78. }
  79. __classPrivateFieldSet(this, _RedisClusterSlots_isOpen, true, "f");
  80. try {
  81. await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverWithRootNodes).call(this);
  82. }
  83. catch (err) {
  84. __classPrivateFieldSet(this, _RedisClusterSlots_isOpen, false, "f");
  85. throw err;
  86. }
  87. }
  88. nodeClient(node) {
  89. return node.client ?? __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_createNodeClient).call(this, node);
  90. }
  91. async rediscover(startWith) {
  92. __classPrivateFieldSet(this, _RedisClusterSlots_runningRediscoverPromise, __classPrivateFieldGet(this, _RedisClusterSlots_runningRediscoverPromise, "f") ?? __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_rediscover).call(this, startWith)
  93. .finally(() => __classPrivateFieldSet(this, _RedisClusterSlots_runningRediscoverPromise, undefined, "f")), "f");
  94. return __classPrivateFieldGet(this, _RedisClusterSlots_runningRediscoverPromise, "f");
  95. }
  96. quit() {
  97. return __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_destroy).call(this, client => client.quit());
  98. }
  99. disconnect() {
  100. return __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_destroy).call(this, client => client.disconnect());
  101. }
  102. getClient(firstKey, isReadonly) {
  103. if (!firstKey) {
  104. return this.nodeClient(this.getRandomNode());
  105. }
  106. const slotNumber = calculateSlot(firstKey);
  107. if (!isReadonly) {
  108. return this.nodeClient(this.slots[slotNumber].master);
  109. }
  110. return this.nodeClient(this.getSlotRandomNode(slotNumber));
  111. }
  112. getRandomNode() {
  113. __classPrivateFieldSet(this, _RedisClusterSlots_randomNodeIterator, __classPrivateFieldGet(this, _RedisClusterSlots_randomNodeIterator, "f") ?? __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_iterateAllNodes).call(this), "f");
  114. return __classPrivateFieldGet(this, _RedisClusterSlots_randomNodeIterator, "f").next().value;
  115. }
  116. getSlotRandomNode(slotNumber) {
  117. const slot = this.slots[slotNumber];
  118. if (!slot.replicas?.length) {
  119. return slot.master;
  120. }
  121. slot.nodesIterator ?? (slot.nodesIterator = __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_slotNodesIterator).call(this, slot));
  122. return slot.nodesIterator.next().value;
  123. }
  124. getMasterByAddress(address) {
  125. const master = this.nodeByAddress.get(address);
  126. if (!master)
  127. return;
  128. return this.nodeClient(master);
  129. }
  130. getPubSubClient() {
  131. return this.pubSubNode ?
  132. this.pubSubNode.client :
  133. __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiatePubSubClient).call(this);
  134. }
  135. async executeUnsubscribeCommand(unsubscribe) {
  136. const client = await this.getPubSubClient();
  137. await unsubscribe(client);
  138. if (!client.isPubSubActive && client.isOpen) {
  139. await client.disconnect();
  140. this.pubSubNode = undefined;
  141. }
  142. }
  143. getShardedPubSubClient(channel) {
  144. const { master } = this.slots[calculateSlot(channel)];
  145. return master.pubSubClient ?? __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiateShardedPubSubClient).call(this, master);
  146. }
  147. async executeShardedUnsubscribeCommand(channel, unsubscribe) {
  148. const { master } = this.slots[calculateSlot(channel)];
  149. if (!master.pubSubClient)
  150. return Promise.resolve();
  151. const client = await master.pubSubClient;
  152. await unsubscribe(client);
  153. if (!client.isPubSubActive && client.isOpen) {
  154. await client.disconnect();
  155. master.pubSubClient = undefined;
  156. }
  157. }
  158. }
  159. _a = RedisClusterSlots, _RedisClusterSlots_options = new WeakMap(), _RedisClusterSlots_Client = new WeakMap(), _RedisClusterSlots_emit = new WeakMap(), _RedisClusterSlots_isOpen = new WeakMap(), _RedisClusterSlots_runningRediscoverPromise = new WeakMap(), _RedisClusterSlots_randomNodeIterator = new WeakMap(), _RedisClusterSlots_instances = new WeakSet(), _RedisClusterSlots_discoverWithRootNodes = async function _RedisClusterSlots_discoverWithRootNodes() {
  160. let start = Math.floor(Math.random() * __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").rootNodes.length);
  161. for (let i = start; i < __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").rootNodes.length; i++) {
  162. if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discover).call(this, __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").rootNodes[i]))
  163. return;
  164. }
  165. for (let i = 0; i < start; i++) {
  166. if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discover).call(this, __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").rootNodes[i]))
  167. return;
  168. }
  169. throw new errors_1.RootNodesUnavailableError();
  170. }, _RedisClusterSlots_resetSlots = function _RedisClusterSlots_resetSlots() {
  171. this.slots = new Array(__classPrivateFieldGet(_a, _a, "f", _RedisClusterSlots_SLOTS));
  172. this.shards = [];
  173. this.masters = [];
  174. this.replicas = [];
  175. __classPrivateFieldSet(this, _RedisClusterSlots_randomNodeIterator, undefined, "f");
  176. }, _RedisClusterSlots_discover = async function _RedisClusterSlots_discover(rootNode) {
  177. __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_resetSlots).call(this);
  178. const addressesInUse = new Set();
  179. try {
  180. const shards = await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_getShards).call(this, rootNode), promises = [], eagerConnect = __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").minimizeConnections !== true;
  181. for (const { from, to, master, replicas } of shards) {
  182. const shard = {
  183. master: __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiateSlotNode).call(this, master, false, eagerConnect, addressesInUse, promises)
  184. };
  185. if (__classPrivateFieldGet(this, _RedisClusterSlots_options, "f").useReplicas) {
  186. shard.replicas = replicas.map(replica => __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiateSlotNode).call(this, replica, true, eagerConnect, addressesInUse, promises));
  187. }
  188. this.shards.push(shard);
  189. for (let i = from; i <= to; i++) {
  190. this.slots[i] = shard;
  191. }
  192. }
  193. if (this.pubSubNode && !addressesInUse.has(this.pubSubNode.address)) {
  194. if (util_1.types.isPromise(this.pubSubNode.client)) {
  195. promises.push(this.pubSubNode.client.then(client => client.disconnect()));
  196. this.pubSubNode = undefined;
  197. }
  198. else {
  199. promises.push(this.pubSubNode.client.disconnect());
  200. const channelsListeners = this.pubSubNode.client.getPubSubListeners(pub_sub_1.PubSubType.CHANNELS), patternsListeners = this.pubSubNode.client.getPubSubListeners(pub_sub_1.PubSubType.PATTERNS);
  201. if (channelsListeners.size || patternsListeners.size) {
  202. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiatePubSubClient).call(this, {
  203. [pub_sub_1.PubSubType.CHANNELS]: channelsListeners,
  204. [pub_sub_1.PubSubType.PATTERNS]: patternsListeners
  205. }));
  206. }
  207. }
  208. }
  209. for (const [address, node] of this.nodeByAddress.entries()) {
  210. if (addressesInUse.has(address))
  211. continue;
  212. if (node.client) {
  213. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, node.client, client => client.disconnect()));
  214. }
  215. const { pubSubClient } = node;
  216. if (pubSubClient) {
  217. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, pubSubClient, client => client.disconnect()));
  218. }
  219. this.nodeByAddress.delete(address);
  220. }
  221. await Promise.all(promises);
  222. return true;
  223. }
  224. catch (err) {
  225. __classPrivateFieldGet(this, _RedisClusterSlots_emit, "f").call(this, 'error', err);
  226. return false;
  227. }
  228. }, _RedisClusterSlots_getShards = async function _RedisClusterSlots_getShards(rootNode) {
  229. const client = new (__classPrivateFieldGet(this, _RedisClusterSlots_Client, "f"))(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_clientOptionsDefaults).call(this, rootNode, true));
  230. client.on('error', err => __classPrivateFieldGet(this, _RedisClusterSlots_emit, "f").call(this, 'error', err));
  231. await client.connect();
  232. try {
  233. // using `CLUSTER SLOTS` and not `CLUSTER SHARDS` to support older versions
  234. return await client.clusterSlots();
  235. }
  236. finally {
  237. await client.disconnect();
  238. }
  239. }, _RedisClusterSlots_getNodeAddress = function _RedisClusterSlots_getNodeAddress(address) {
  240. switch (typeof __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").nodeAddressMap) {
  241. case 'object':
  242. return __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").nodeAddressMap[address];
  243. case 'function':
  244. return __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").nodeAddressMap(address);
  245. }
  246. }, _RedisClusterSlots_clientOptionsDefaults = function _RedisClusterSlots_clientOptionsDefaults(options, disableReconnect) {
  247. let result;
  248. if (__classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults) {
  249. let socket;
  250. if (__classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket) {
  251. socket = options?.socket ? {
  252. ...__classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket,
  253. ...options.socket
  254. } : __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket;
  255. }
  256. else {
  257. socket = options?.socket;
  258. }
  259. result = {
  260. ...__classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults,
  261. ...options,
  262. socket
  263. };
  264. }
  265. else {
  266. result = options;
  267. }
  268. if (disableReconnect) {
  269. result ?? (result = {});
  270. result.socket ?? (result.socket = {});
  271. result.socket.reconnectStrategy = false;
  272. }
  273. return result;
  274. }, _RedisClusterSlots_initiateSlotNode = function _RedisClusterSlots_initiateSlotNode({ id, ip, port }, readonly, eagerConnent, addressesInUse, promises) {
  275. const address = `${ip}:${port}`;
  276. addressesInUse.add(address);
  277. let node = this.nodeByAddress.get(address);
  278. if (!node) {
  279. node = {
  280. id,
  281. host: ip,
  282. port,
  283. address,
  284. readonly,
  285. client: undefined
  286. };
  287. if (eagerConnent) {
  288. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_createNodeClient).call(this, node));
  289. }
  290. this.nodeByAddress.set(address, node);
  291. }
  292. (readonly ? this.replicas : this.masters).push(node);
  293. return node;
  294. }, _RedisClusterSlots_createClient = async function _RedisClusterSlots_createClient(node, readonly = node.readonly) {
  295. const client = new (__classPrivateFieldGet(this, _RedisClusterSlots_Client, "f"))(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_clientOptionsDefaults).call(this, {
  296. socket: __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_getNodeAddress).call(this, node.address) ?? {
  297. host: node.host,
  298. port: node.port
  299. },
  300. readonly
  301. }));
  302. client.on('error', err => __classPrivateFieldGet(this, _RedisClusterSlots_emit, "f").call(this, 'error', err));
  303. await client.connect();
  304. return client;
  305. }, _RedisClusterSlots_createNodeClient = function _RedisClusterSlots_createNodeClient(node) {
  306. const promise = __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_createClient).call(this, node)
  307. .then(client => {
  308. node.client = client;
  309. return client;
  310. })
  311. .catch(err => {
  312. node.client = undefined;
  313. throw err;
  314. });
  315. node.client = promise;
  316. return promise;
  317. }, _RedisClusterSlots_rediscover = async function _RedisClusterSlots_rediscover(startWith) {
  318. if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discover).call(this, startWith.options))
  319. return;
  320. return __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverWithRootNodes).call(this);
  321. }, _RedisClusterSlots_destroy = async function _RedisClusterSlots_destroy(fn) {
  322. __classPrivateFieldSet(this, _RedisClusterSlots_isOpen, false, "f");
  323. const promises = [];
  324. for (const { master, replicas } of this.shards) {
  325. if (master.client) {
  326. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, master.client, fn));
  327. }
  328. if (master.pubSubClient) {
  329. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, master.pubSubClient, fn));
  330. }
  331. if (replicas) {
  332. for (const { client } of replicas) {
  333. if (client) {
  334. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, client, fn));
  335. }
  336. }
  337. }
  338. }
  339. if (this.pubSubNode) {
  340. promises.push(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_execOnNodeClient).call(this, this.pubSubNode.client, fn));
  341. this.pubSubNode = undefined;
  342. }
  343. __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_resetSlots).call(this);
  344. this.nodeByAddress.clear();
  345. await Promise.allSettled(promises);
  346. }, _RedisClusterSlots_execOnNodeClient = function _RedisClusterSlots_execOnNodeClient(client, fn) {
  347. return util_1.types.isPromise(client) ?
  348. client.then(fn) :
  349. fn(client);
  350. }, _RedisClusterSlots_iterateAllNodes = function* _RedisClusterSlots_iterateAllNodes() {
  351. let i = Math.floor(Math.random() * (this.masters.length + this.replicas.length));
  352. if (i < this.masters.length) {
  353. do {
  354. yield this.masters[i];
  355. } while (++i < this.masters.length);
  356. for (const replica of this.replicas) {
  357. yield replica;
  358. }
  359. }
  360. else {
  361. i -= this.masters.length;
  362. do {
  363. yield this.replicas[i];
  364. } while (++i < this.replicas.length);
  365. }
  366. while (true) {
  367. for (const master of this.masters) {
  368. yield master;
  369. }
  370. for (const replica of this.replicas) {
  371. yield replica;
  372. }
  373. }
  374. }, _RedisClusterSlots_slotNodesIterator = function* _RedisClusterSlots_slotNodesIterator(slot) {
  375. let i = Math.floor(Math.random() * (1 + slot.replicas.length));
  376. if (i < slot.replicas.length) {
  377. do {
  378. yield slot.replicas[i];
  379. } while (++i < slot.replicas.length);
  380. }
  381. while (true) {
  382. yield slot.master;
  383. for (const replica of slot.replicas) {
  384. yield replica;
  385. }
  386. }
  387. }, _RedisClusterSlots_initiatePubSubClient = async function _RedisClusterSlots_initiatePubSubClient(toResubscribe) {
  388. const index = Math.floor(Math.random() * (this.masters.length + this.replicas.length)), node = index < this.masters.length ?
  389. this.masters[index] :
  390. this.replicas[index - this.masters.length];
  391. this.pubSubNode = {
  392. address: node.address,
  393. client: __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_createClient).call(this, node, true)
  394. .then(async (client) => {
  395. if (toResubscribe) {
  396. await Promise.all([
  397. client.extendPubSubListeners(pub_sub_1.PubSubType.CHANNELS, toResubscribe[pub_sub_1.PubSubType.CHANNELS]),
  398. client.extendPubSubListeners(pub_sub_1.PubSubType.PATTERNS, toResubscribe[pub_sub_1.PubSubType.PATTERNS])
  399. ]);
  400. }
  401. this.pubSubNode.client = client;
  402. return client;
  403. })
  404. .catch(err => {
  405. this.pubSubNode = undefined;
  406. throw err;
  407. })
  408. };
  409. return this.pubSubNode.client;
  410. }, _RedisClusterSlots_initiateShardedPubSubClient = function _RedisClusterSlots_initiateShardedPubSubClient(master) {
  411. const promise = __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_createClient).call(this, master, true)
  412. .then(client => {
  413. client.on('server-sunsubscribe', async (channel, listeners) => {
  414. try {
  415. await this.rediscover(client);
  416. const redirectTo = await this.getShardedPubSubClient(channel);
  417. redirectTo.extendPubSubChannelListeners(pub_sub_1.PubSubType.SHARDED, channel, listeners);
  418. }
  419. catch (err) {
  420. __classPrivateFieldGet(this, _RedisClusterSlots_emit, "f").call(this, 'sharded-shannel-moved-error', err, channel, listeners);
  421. }
  422. });
  423. master.pubSubClient = client;
  424. return client;
  425. })
  426. .catch(err => {
  427. master.pubSubClient = undefined;
  428. throw err;
  429. });
  430. master.pubSubClient = promise;
  431. return promise;
  432. };
  433. _RedisClusterSlots_SLOTS = { value: 16384 };
  434. exports.default = RedisClusterSlots;