ClusterOptions.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /// <reference types="node" />
  2. import { SrvRecord } from "dns";
  3. import { RedisOptions } from "../redis/RedisOptions";
  4. import { CommanderOptions } from "../utils/Commander";
  5. import { NodeRole } from "./util";
  6. export declare type DNSResolveSrvFunction = (hostname: string, callback: (err: NodeJS.ErrnoException | null | undefined, records?: SrvRecord[]) => void) => void;
  7. export declare type DNSLookupFunction = (hostname: string, callback: (err: NodeJS.ErrnoException | null | undefined, address: string, family?: number) => void) => void;
  8. export declare type NatMapFunction = (key: string) => {
  9. host: string;
  10. port: number;
  11. } | null;
  12. export declare type NatMap = {
  13. [key: string]: {
  14. host: string;
  15. port: number;
  16. };
  17. } | NatMapFunction;
  18. /**
  19. * Options for Cluster constructor
  20. */
  21. export interface ClusterOptions extends CommanderOptions {
  22. /**
  23. * See "Quick Start" section.
  24. *
  25. * @default (times) => Math.min(100 + times * 2, 2000)
  26. */
  27. clusterRetryStrategy?: ((times: number, reason?: Error) => number | void | null) | undefined;
  28. /**
  29. * See Redis class.
  30. *
  31. * @default true
  32. */
  33. enableOfflineQueue?: boolean | undefined;
  34. /**
  35. * When enabled, ioredis only emits "ready" event when `CLUSTER INFO`
  36. * command reporting the cluster is ready for handling commands.
  37. *
  38. * @default true
  39. */
  40. enableReadyCheck?: boolean | undefined;
  41. /**
  42. * Scale reads to the node with the specified role.
  43. *
  44. * @default "master"
  45. */
  46. scaleReads?: NodeRole | Function | undefined;
  47. /**
  48. * When a MOVED or ASK error is received, client will redirect the
  49. * command to another node.
  50. * This option limits the max redirections allowed to send a command.
  51. *
  52. * @default 16
  53. */
  54. maxRedirections?: number | undefined;
  55. /**
  56. * When an error is received when sending a command (e.g.
  57. * "Connection is closed." when the target Redis node is down), client will retry
  58. * if `retryDelayOnFailover` is valid delay time (in ms).
  59. *
  60. * @default 100
  61. */
  62. retryDelayOnFailover?: number | undefined;
  63. /**
  64. * When a CLUSTERDOWN error is received, client will retry
  65. * if `retryDelayOnClusterDown` is valid delay time (in ms).
  66. *
  67. * @default 100
  68. */
  69. retryDelayOnClusterDown?: number | undefined;
  70. /**
  71. * When a TRYAGAIN error is received, client will retry
  72. * if `retryDelayOnTryAgain` is valid delay time (in ms).
  73. *
  74. * @default 100
  75. */
  76. retryDelayOnTryAgain?: number | undefined;
  77. /**
  78. * By default, this value is 0, which means when a `MOVED` error is received,
  79. * the client will resend the command instantly to the node returned together with
  80. * the `MOVED` error. However, sometimes it takes time for a cluster to become
  81. * state stabilized after a failover, so adding a delay before resending can
  82. * prevent a ping pong effect.
  83. *
  84. * @default 0
  85. */
  86. retryDelayOnMoved?: number | undefined;
  87. /**
  88. * The milliseconds before a timeout occurs while refreshing
  89. * slots from the cluster.
  90. *
  91. * @default 1000
  92. */
  93. slotsRefreshTimeout?: number | undefined;
  94. /**
  95. * The milliseconds between every automatic slots refresh.
  96. *
  97. * @default 5000
  98. */
  99. slotsRefreshInterval?: number | undefined;
  100. /**
  101. * Use sharded subscribers instead of a single subscriber.
  102. *
  103. * If sharded subscribers are used, then one additional subscriber connection per master node
  104. * is established. If you don't plan to use SPUBLISH/SSUBSCRIBE, then this should be disabled.
  105. *
  106. * @default false
  107. */
  108. shardedSubscribers?: boolean | undefined;
  109. /**
  110. * Passed to the constructor of `Redis`
  111. *
  112. * @default null
  113. */
  114. redisOptions?: Omit<RedisOptions, "port" | "host" | "path" | "sentinels" | "retryStrategy" | "enableOfflineQueue" | "readOnly"> | undefined;
  115. /**
  116. * By default, When a new Cluster instance is created,
  117. * it will connect to the Redis cluster automatically.
  118. * If you want to keep the instance disconnected until the first command is called,
  119. * set this option to `true`.
  120. *
  121. * @default false
  122. */
  123. lazyConnect?: boolean | undefined;
  124. /**
  125. * Discover nodes using SRV records
  126. *
  127. * @default false
  128. */
  129. useSRVRecords?: boolean | undefined;
  130. /**
  131. * SRV records will be resolved via this function.
  132. *
  133. * You may provide a custom `resolveSrv` function when you want to customize
  134. * the cache behavior of the default function.
  135. *
  136. * @default require('dns').resolveSrv
  137. */
  138. resolveSrv?: DNSResolveSrvFunction | undefined;
  139. /**
  140. * Hostnames will be resolved to IP addresses via this function.
  141. * This is needed when the addresses of startup nodes are hostnames instead
  142. * of IPs.
  143. *
  144. * You may provide a custom `lookup` function when you want to customize
  145. * the cache behavior of the default function.
  146. *
  147. * @default require('dns').lookup
  148. */
  149. dnsLookup?: DNSLookupFunction | undefined;
  150. natMap?: NatMap | undefined;
  151. /**
  152. * See Redis class.
  153. *
  154. * @default false
  155. */
  156. enableAutoPipelining?: boolean | undefined;
  157. /**
  158. * See Redis class.
  159. *
  160. * @default []
  161. */
  162. autoPipeliningIgnoredCommands?: string[] | undefined;
  163. /**
  164. * Custom LUA commands
  165. */
  166. scripts?: Record<string, {
  167. lua: string;
  168. numberOfKeys?: number;
  169. readOnly?: boolean;
  170. }> | undefined;
  171. }
  172. export declare const DEFAULT_CLUSTER_OPTIONS: ClusterOptions;