@@ -94,7 +94,7 @@ await cluster.set('foo', 'bar');
9494const value = await cluster .get (' foo' );
9595console .log (value); // returns 'bar'
9696
97- await cluster .quit ();
97+ await cluster .close ();
9898```
9999
100100## Connect to your production Redis with TLS
@@ -123,15 +123,21 @@ await client.set('foo', 'bar');
123123const value = await client .get (' foo' );
124124console .log (value) // returns 'bar'
125125
126- await client .disconnect ();
126+ await client .destroy ();
127127```
128128
129129You can also use discrete parameters and UNIX sockets. Details can be found in the [ client configuration guide] ( https://github.com/redis/node-redis/blob/master/docs/client-configuration.md ) .
130130
131131## Reconnect after disconnection
132132
133- By default, ` node-redis ` doesn't attempt to reconnect automatically when
134- the connection to the server is lost. However, you can set the
133+ ` node-redis ` can attempt to reconnect automatically when
134+ the connection to the server is lost. By default, it will retry
135+ the connection using an
136+ [ exponential backoff] ( https://en.wikipedia.org/wiki/Exponential_backoff )
137+ strategy with some random "jitter" added to avoid multiple
138+ clients retrying in sync with each other.
139+
140+ You can also set the
135141` socket.reconnectionStrategy ` field in the configuration to decide
136142whether to try to reconnect and how to approach it. Choose one of the following values for
137143` socket.reconnectionStrategy ` :
@@ -159,19 +165,18 @@ from the function can be any of the following:
159165 no attempt was made to reconnect.
160166
161167The example below shows a ` reconnectionStrategy ` function that implements a
162- custom [ exponential backoff] ( https://en.wikipedia.org/wiki/Exponential_backoff )
163- strategy:
168+ custom exponential backoff strategy:
164169
165170``` js
166171createClient ({
167172 socket: {
168173 reconnectStrategy : retries => {
169- // Generate a random jitter between 0 – 200 ms:
170- const jitter = Math .floor (Math .random () * 200 );
174+ // Generate a random jitter between 0 – 100 ms:
175+ const jitter = Math .floor (Math .random () * 100 );
171176
172- // Delay is an exponential back off , (times^2 ) * 50 ms, with a
173- // maximum value of 2000 ms:
174- const delay = Math .min (Math .pow (2 , retries) * 50 , 2000 );
177+ // Delay is an exponential backoff , (2^retries ) * 50 ms, with a
178+ // maximum value of 3000 ms:
179+ const delay = Math .min (Math .pow (2 , retries) * 50 , 3000 );
175180
176181 return delay + jitter;
177182 }
@@ -193,6 +198,12 @@ related to connection:
193198 parameter. This is usually a network issue such as "Socket closed unexpectedly".
194199- ` reconnecting ` : (No parameters) The client is about to try reconnecting after the
195200 connection was lost due to an error.
201+ - ` sharded-channel-moved ` : The cluster slot of a subscribed
202+ [ sharded pub/sub channel] ({{< relref "/develop/interact/pubsub#sharded-pubsub" >}})
203+ has been moved to another shard. Note that when you use a
204+ [ ` RedisCluster ` ] ( #connect-to-a-redis-cluster ) connection, this event is automatically
205+ handled for you. See
206+ [ ` sharded-channel-moved ` event] ( https://github.com/redis/node-redis/blob/master/docs/pub-sub.md#sharded-channel-moved-event ) for more information.
196207
197208Use code like the following to respond to these events:
198209
0 commit comments