index.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /// <reference types="node" />
  2. import { EventEmitter } from "events";
  3. import Command from "../Command";
  4. import Redis from "../Redis";
  5. import ScanStream from "../ScanStream";
  6. import { Transaction } from "../transaction";
  7. import { Callback, ScanStreamOptions, WriteableStream } from "../types";
  8. import Commander from "../utils/Commander";
  9. import { ClusterOptions } from "./ClusterOptions";
  10. import { NodeKey, NodeRole } from "./util";
  11. export declare type ClusterNode = string | number | {
  12. host?: string | undefined;
  13. port?: number | undefined;
  14. };
  15. declare type ClusterStatus = "end" | "close" | "wait" | "connecting" | "connect" | "ready" | "reconnecting" | "disconnecting";
  16. /**
  17. * Client for the official Redis Cluster
  18. */
  19. declare class Cluster extends Commander {
  20. options: ClusterOptions;
  21. slots: NodeKey[][];
  22. status: ClusterStatus;
  23. /**
  24. * @ignore
  25. */
  26. _groupsIds: {
  27. [key: string]: number;
  28. };
  29. /**
  30. * @ignore
  31. */
  32. _groupsBySlot: number[];
  33. /**
  34. * @ignore
  35. */
  36. isCluster: boolean;
  37. private startupNodes;
  38. private connectionPool;
  39. private manuallyClosing;
  40. private retryAttempts;
  41. private delayQueue;
  42. private offlineQueue;
  43. private subscriber;
  44. private shardedSubscribers;
  45. private slotsTimer;
  46. private reconnectTimeout;
  47. private isRefreshing;
  48. private _refreshSlotsCacheCallbacks;
  49. private _autoPipelines;
  50. private _runningAutoPipelines;
  51. private _readyDelayedCallbacks;
  52. private subscriberGroupEmitter;
  53. /**
  54. * Every time Cluster#connect() is called, this value will be
  55. * auto-incrementing. The purpose of this value is used for
  56. * discarding previous connect attampts when creating a new
  57. * connection.
  58. */
  59. private connectionEpoch;
  60. /**
  61. * Creates an instance of Cluster.
  62. */
  63. constructor(startupNodes: ClusterNode[], options?: ClusterOptions);
  64. /**
  65. * Connect to a cluster
  66. */
  67. connect(): Promise<void>;
  68. /**
  69. * Disconnect from every node in the cluster.
  70. */
  71. disconnect(reconnect?: boolean): void;
  72. /**
  73. * Quit the cluster gracefully.
  74. */
  75. quit(callback?: Callback<"OK">): Promise<"OK">;
  76. /**
  77. * Create a new instance with the same startup nodes and options as the current one.
  78. *
  79. * @example
  80. * ```js
  81. * var cluster = new Redis.Cluster([{ host: "127.0.0.1", port: "30001" }]);
  82. * var anotherCluster = cluster.duplicate();
  83. * ```
  84. */
  85. duplicate(overrideStartupNodes?: any[], overrideOptions?: {}): Cluster;
  86. /**
  87. * Get nodes with the specified role
  88. */
  89. nodes(role?: NodeRole): Redis[];
  90. /**
  91. * This is needed in order not to install a listener for each auto pipeline
  92. *
  93. * @ignore
  94. */
  95. delayUntilReady(callback: Callback): void;
  96. /**
  97. * Get the number of commands queued in automatic pipelines.
  98. *
  99. * This is not available (and returns 0) until the cluster is connected and slots information have been received.
  100. */
  101. get autoPipelineQueueSize(): number;
  102. /**
  103. * Refresh the slot cache
  104. *
  105. * @ignore
  106. */
  107. refreshSlotsCache(callback?: Callback<void>): void;
  108. /**
  109. * @ignore
  110. */
  111. sendCommand(command: Command, stream?: WriteableStream, node?: any): unknown;
  112. sscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  113. sscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  114. hscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  115. hscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  116. zscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  117. zscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  118. /**
  119. * @ignore
  120. */
  121. handleError(error: Error, ttl: {
  122. value?: any;
  123. }, handlers: any): void;
  124. private resetOfflineQueue;
  125. private clearNodesRefreshInterval;
  126. private resetNodesRefreshInterval;
  127. /**
  128. * Change cluster instance's status
  129. */
  130. private setStatus;
  131. /**
  132. * Called when closed to check whether a reconnection should be made
  133. */
  134. private handleCloseEvent;
  135. /**
  136. * Flush offline queue with error.
  137. */
  138. private flushQueue;
  139. private executeOfflineCommands;
  140. private natMapper;
  141. private getInfoFromNode;
  142. private invokeReadyDelayedCallbacks;
  143. /**
  144. * Check whether Cluster is able to process commands
  145. */
  146. private readyCheck;
  147. private resolveSrv;
  148. private dnsLookup;
  149. /**
  150. * Normalize startup nodes, and resolving hostnames to IPs.
  151. *
  152. * This process happens every time when #connect() is called since
  153. * #startupNodes and DNS records may chanage.
  154. */
  155. private resolveStartupNodeHostnames;
  156. private createScanStream;
  157. private createShardedSubscriberGroup;
  158. }
  159. interface Cluster extends EventEmitter {
  160. }
  161. interface Cluster extends Transaction {
  162. }
  163. export default Cluster;