RedisOptions.d.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { CommanderOptions } from "../utils/Commander";
  2. import ConnectorConstructor from "../connectors/ConnectorConstructor";
  3. import { SentinelConnectionOptions } from "../connectors/SentinelConnector";
  4. import { StandaloneConnectionOptions } from "../connectors/StandaloneConnector";
  5. export declare type ReconnectOnError = (err: Error) => boolean | 1 | 2;
  6. export interface CommonRedisOptions extends CommanderOptions {
  7. Connector?: ConnectorConstructor | undefined;
  8. retryStrategy?: ((times: number) => number | void | null) | undefined;
  9. /**
  10. * If a command does not return a reply within a set number of milliseconds,
  11. * a "Command timed out" error will be thrown.
  12. */
  13. commandTimeout?: number | undefined;
  14. /**
  15. * Enables client-side timeout protection for blocking commands when set
  16. * to a positive number. If `blockingTimeout` is undefined, `0`, or
  17. * negative (e.g. `-1`), the protection is disabled and no client-side
  18. * timers are installed for blocking commands.
  19. */
  20. blockingTimeout?: number | undefined;
  21. /**
  22. * Grace period (ms) added to blocking command timeouts. Only used when
  23. * `blockingTimeout` is a positive number. Defaults to 100ms.
  24. */
  25. blockingTimeoutGrace?: number | undefined;
  26. /**
  27. * If the socket does not receive data within a set number of milliseconds:
  28. * 1. the socket is considered "dead" and will be destroyed
  29. * 2. the client will reject any running commands (altought they might have been processed by the server)
  30. * 3. the reconnect strategy will kick in (depending on the configuration)
  31. */
  32. socketTimeout?: number | undefined;
  33. /**
  34. * Enable/disable keep-alive functionality.
  35. * @link https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay
  36. * @default 0
  37. */
  38. keepAlive?: number | undefined;
  39. /**
  40. * Enable/disable the use of Nagle's algorithm.
  41. * @link https://nodejs.org/api/net.html#socketsetnodelaynodelay
  42. * @default true
  43. */
  44. noDelay?: boolean | undefined;
  45. /**
  46. * Set the name of the connection to make it easier to identity the connection
  47. * in client list.
  48. * @link https://redis.io/commands/client-setname
  49. */
  50. connectionName?: string | undefined;
  51. /**
  52. * If true, skips setting library info via CLIENT SETINFO.
  53. * @link https://redis.io/docs/latest/commands/client-setinfo/
  54. * @default false
  55. */
  56. disableClientInfo?: boolean | undefined;
  57. /**
  58. * Tag to append to the library name in CLIENT SETINFO (ioredis(tag)).
  59. * @link https://redis.io/docs/latest/commands/client-setinfo/
  60. * @default undefined
  61. */
  62. clientInfoTag?: string | undefined;
  63. /**
  64. * If set, client will send AUTH command with the value of this option as the first argument when connected.
  65. * This is supported since Redis 6.
  66. */
  67. username?: string | undefined;
  68. /**
  69. * If set, client will send AUTH command with the value of this option when connected.
  70. */
  71. password?: string | undefined;
  72. /**
  73. * Database index to use.
  74. *
  75. * @default 0
  76. */
  77. db?: number | undefined;
  78. /**
  79. * When the client reconnects, channels subscribed in the previous connection will be
  80. * resubscribed automatically if `autoResubscribe` is `true`.
  81. * @default true
  82. */
  83. autoResubscribe?: boolean | undefined;
  84. /**
  85. * Whether or not to resend unfulfilled commands on reconnect.
  86. * Unfulfilled commands are most likely to be blocking commands such as `brpop` or `blpop`.
  87. * @default true
  88. */
  89. autoResendUnfulfilledCommands?: boolean | undefined;
  90. /**
  91. * Whether or not to reconnect on certain Redis errors.
  92. * This options by default is `null`, which means it should never reconnect on Redis errors.
  93. * You can pass a function that accepts an Redis error, and returns:
  94. * - `true` or `1` to trigger a reconnection.
  95. * - `false` or `0` to not reconnect.
  96. * - `2` to reconnect and resend the failed command (who triggered the error) after reconnection.
  97. * @example
  98. * ```js
  99. * const redis = new Redis({
  100. * reconnectOnError(err) {
  101. * const targetError = "READONLY";
  102. * if (err.message.includes(targetError)) {
  103. * // Only reconnect when the error contains "READONLY"
  104. * return true; // or `return 1;`
  105. * }
  106. * },
  107. * });
  108. * ```
  109. * @default null
  110. */
  111. reconnectOnError?: ReconnectOnError | null | undefined;
  112. /**
  113. * @default false
  114. */
  115. readOnly?: boolean | undefined;
  116. /**
  117. * When enabled, numbers returned by Redis will be converted to JavaScript strings instead of numbers.
  118. * This is necessary if you want to handle big numbers (above `Number.MAX_SAFE_INTEGER` === 2^53).
  119. * @default false
  120. */
  121. stringNumbers?: boolean | undefined;
  122. /**
  123. * How long the client will wait before killing a socket due to inactivity during initial connection.
  124. * @default 10000
  125. */
  126. connectTimeout?: number | undefined;
  127. /**
  128. * This option is used internally when you call `redis.monitor()` to tell Redis
  129. * to enter the monitor mode when the connection is established.
  130. *
  131. * @default false
  132. */
  133. monitor?: boolean | undefined;
  134. /**
  135. * The commands that don't get a reply due to the connection to the server is lost are
  136. * put into a queue and will be resent on reconnect (if allowed by the `retryStrategy` option).
  137. * This option is used to configure how many reconnection attempts should be allowed before
  138. * the queue is flushed with a `MaxRetriesPerRequestError` error.
  139. * Set this options to `null` instead of a number to let commands wait forever
  140. * until the connection is alive again.
  141. *
  142. * @default 20
  143. */
  144. maxRetriesPerRequest?: number | null | undefined;
  145. /**
  146. * @default 10000
  147. */
  148. maxLoadingRetryTime?: number | undefined;
  149. /**
  150. * @default false
  151. */
  152. enableAutoPipelining?: boolean | undefined;
  153. /**
  154. * @default []
  155. */
  156. autoPipeliningIgnoredCommands?: string[] | undefined;
  157. offlineQueue?: boolean | undefined;
  158. commandQueue?: boolean | undefined;
  159. /**
  160. *
  161. * By default, if the connection to Redis server has not been established, commands are added to a queue
  162. * and are executed once the connection is "ready" (when `enableReadyCheck` is true, "ready" means
  163. * the Redis server has loaded the database from disk, otherwise means the connection to the Redis
  164. * server has been established). If this option is false, when execute the command when the connection
  165. * isn't ready, an error will be returned.
  166. *
  167. * @default true
  168. */
  169. enableOfflineQueue?: boolean | undefined;
  170. /**
  171. * The client will sent an INFO command to check whether the server is still loading data from the disk (
  172. * which happens when the server is just launched) when the connection is established, and only wait until
  173. * the loading process is finished before emitting the `ready` event.
  174. *
  175. * @default true
  176. */
  177. enableReadyCheck?: boolean | undefined;
  178. /**
  179. * When a Redis instance is initialized, a connection to the server is immediately established. Set this to
  180. * true will delay the connection to the server until the first command is sent or `redis.connect()` is called
  181. * explicitly. When `redis.connect()` is called explicitly, a Promise is returned, which will be resolved
  182. * when the connection is ready or rejected when it fails. The rejection should be handled by the user.
  183. *
  184. * @default false
  185. */
  186. lazyConnect?: boolean | undefined;
  187. /**
  188. * @default undefined
  189. */
  190. scripts?: Record<string, {
  191. lua: string;
  192. numberOfKeys?: number | undefined;
  193. readOnly?: boolean | undefined;
  194. }> | undefined;
  195. }
  196. export declare type RedisOptions = CommonRedisOptions & SentinelConnectionOptions & StandaloneConnectionOptions;
  197. export declare const DEFAULT_REDIS_OPTIONS: RedisOptions;