index.d.ts 4.7 KB

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