Skip to content

Commit 7d60f00

Browse files
authored
Updated connect method docs (#1990)
* docs: updated connect method jsdoc and readme * docs: updated lazyConnect jsdoc and updated the readme * docs: adjusted the lazyConnect jsdoc * docs: typo fix
1 parent 40ae7ee commit 7d60f00

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ The Redis instance will emit some events about the state of the connection to th
826826
| :----------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
827827
| connect | emits when a connection is established to the Redis server. |
828828
| ready | If `enableReadyCheck` is `true`, client will emit `ready` when the server reports that it is ready to receive commands (e.g. finish loading data from disk).<br>Otherwise, `ready` will be emitted immediately right after the `connect` event. |
829-
| error | emits when an error occurs while connecting.<br>However, ioredis emits all `error` events silently (only emits when there's at least one listener) so that your application won't crash if you're not listening to the `error` event. |
829+
| error | emits when an error occurs while connecting.<br>When `lazyConnect` is false, ioredis emits all `error` events silently (only emits when there's at least one listener) so that your application won't crash if you're not listening to the `error` event.<br> However when `lazyConnect` is true and `redis.connect()` is explicitly called it will return a promise which might reject with an error. If `redis.connect()` is not called explicitly, ioredis will try to connect automatically on the first command and emit the `error` event silently. |
830830
| close | emits when an established Redis server connection has closed. |
831831
| reconnecting | emits after `close` when a reconnection will be made. The argument of the event is the time (in ms) before reconnecting. |
832832
| end | emits after `close` when no more reconnections will be made, or the connection is failed to establish. |

lib/Redis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class Redis extends Commander implements DataHandledable {
170170
* unless `lazyConnect: true` is passed.
171171
*
172172
* When calling this method manually, a Promise is returned, which will
173-
* be resolved when the connection status is ready.
173+
* be resolved when the connection status is ready. The promise can reject
174+
* if the connection fails, times out, or if Redis is already connecting/connected.
174175
*/
175176
connect(callback?: Callback<void>): Promise<void> {
176177
const promise = new Promise<void>((resolve, reject) => {

lib/redis/RedisOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ export interface CommonRedisOptions extends CommanderOptions {
174174
/**
175175
* When a Redis instance is initialized, a connection to the server is immediately established. Set this to
176176
* true will delay the connection to the server until the first command is sent or `redis.connect()` is called
177-
* explicitly.
177+
* explicitly. When `redis.connect()` is called explicitly, a Promise is returned, which will be resolved
178+
* when the connection is ready or rejected when it fails. The rejection should be handled by the user.
178179
*
179180
* @default false
180181
*/

0 commit comments

Comments
 (0)