index.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 slotsTimer;
  45. private reconnectTimeout;
  46. private isRefreshing;
  47. private _refreshSlotsCacheCallbacks;
  48. private _autoPipelines;
  49. private _runningAutoPipelines;
  50. private _readyDelayedCallbacks;
  51. /**
  52. * Every time Cluster#connect() is called, this value will be
  53. * auto-incrementing. The purpose of this value is used for
  54. * discarding previous connect attampts when creating a new
  55. * connection.
  56. */
  57. private connectionEpoch;
  58. /**
  59. * Creates an instance of Cluster.
  60. */
  61. constructor(startupNodes: ClusterNode[], options?: ClusterOptions);
  62. /**
  63. * Connect to a cluster
  64. */
  65. connect(): Promise<void>;
  66. /**
  67. * Disconnect from every node in the cluster.
  68. */
  69. disconnect(reconnect?: boolean): void;
  70. /**
  71. * Quit the cluster gracefully.
  72. */
  73. quit(callback?: Callback<"OK">): Promise<"OK">;
  74. /**
  75. * Create a new instance with the same startup nodes and options as the current one.
  76. *
  77. * @example
  78. * ```js
  79. * var cluster = new Redis.Cluster([{ host: "127.0.0.1", port: "30001" }]);
  80. * var anotherCluster = cluster.duplicate();
  81. * ```
  82. */
  83. duplicate(overrideStartupNodes?: any[], overrideOptions?: {}): Cluster;
  84. /**
  85. * Get nodes with the specified role
  86. */
  87. nodes(role?: NodeRole): Redis[];
  88. /**
  89. * This is needed in order not to install a listener for each auto pipeline
  90. *
  91. * @ignore
  92. */
  93. delayUntilReady(callback: Callback): void;
  94. /**
  95. * Get the number of commands queued in automatic pipelines.
  96. *
  97. * This is not available (and returns 0) until the cluster is connected and slots information have been received.
  98. */
  99. get autoPipelineQueueSize(): number;
  100. /**
  101. * Refresh the slot cache
  102. *
  103. * @ignore
  104. */
  105. refreshSlotsCache(callback?: Callback<void>): void;
  106. /**
  107. * @ignore
  108. */
  109. sendCommand(command: Command, stream?: WriteableStream, node?: any): unknown;
  110. sscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  111. sscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  112. hscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  113. hscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  114. zscanStream(key: string, options?: ScanStreamOptions): ScanStream;
  115. zscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
  116. /**
  117. * @ignore
  118. */
  119. handleError(error: Error, ttl: {
  120. value?: any;
  121. }, handlers: any): void;
  122. private resetOfflineQueue;
  123. private clearNodesRefreshInterval;
  124. private resetNodesRefreshInterval;
  125. /**
  126. * Change cluster instance's status
  127. */
  128. private setStatus;
  129. /**
  130. * Called when closed to check whether a reconnection should be made
  131. */
  132. private handleCloseEvent;
  133. /**
  134. * Flush offline queue with error.
  135. */
  136. private flushQueue;
  137. private executeOfflineCommands;
  138. private natMapper;
  139. private getInfoFromNode;
  140. private invokeReadyDelayedCallbacks;
  141. /**
  142. * Check whether Cluster is able to process commands
  143. */
  144. private readyCheck;
  145. private resolveSrv;
  146. private dnsLookup;
  147. /**
  148. * Normalize startup nodes, and resolving hostnames to IPs.
  149. *
  150. * This process happens every time when #connect() is called since
  151. * #startupNodes and DNS records may chanage.
  152. */
  153. private resolveStartupNodeHostnames;
  154. private createScanStream;
  155. }
  156. interface Cluster extends EventEmitter {
  157. }
  158. interface Cluster extends Transaction {
  159. }
  160. export default Cluster;