You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-3Lines changed: 33 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,10 +216,11 @@ limits total amount of connection tries. Setting this to 1 will prevent any reco
216
216
*`tls`: an object containing options to pass to [tls.connect](http://nodejs.org/api/tls.html#tls_tls_connect_port_host_options_callback),
217
217
to set up a TLS connection to Redis (if, for example, it is set up to be accessible via a tunnel).
218
218
*`prefix`: *null*; pass a string to prefix all used keys with that string as prefix e.g. 'namespace:test'
219
+
*`retry_strategy`: *function*; pass a function that receives a options object as parameter including the retry `attempt`, the `total_retry_time` indicating how much time passed since the last time connected, the `error` why the connection was lost and the number of `times_connected` in total. If you return a number from this function, the retry will happen exactly after that time in milliseconds. If you return a non-number no further retry is going to happen and all offline commands are flushed with errors. Return a error to return that specific error to all offline commands. Check out the example too.
var client =redis.createClient({detect_buffers:true});
223
224
224
225
client.set("foo_rand000000000000", "OK");
225
226
@@ -235,6 +236,28 @@ client.get(new Buffer("foo_rand000000000000"), function (err, reply) {
235
236
client.end();
236
237
```
237
238
239
+
retry_strategy example
240
+
```js
241
+
var client =redis.createClient({
242
+
retry_strategy:function (options) {
243
+
if (options.error.code==='ECONNREFUSED') {
244
+
// End reconnecting on a specific error and flush all commands with a individual error
245
+
returnnewError('The server refused the connection');
246
+
}
247
+
if (options.total_retry_time>1000*60*60) {
248
+
// End reconnecting after a specific timeout and flush all commands with a individual error
249
+
returnnewError('Retry time exhausted');
250
+
}
251
+
if (options.times_connected>10) {
252
+
// End reconnecting with built in error
253
+
returnundefined;
254
+
}
255
+
// reconnect after
256
+
returnMath.max(options.attempt*100, 3000);
257
+
}
258
+
});
259
+
```
260
+
238
261
## client.auth(password[, callback])
239
262
240
263
When connecting to a Redis server that requires authentication, the `AUTH` command must be sent as the
@@ -246,6 +269,13 @@ NOTE: Your call to `client.auth()` should not be inside the ready handler. If
246
269
you are doing this wrong, `client` will emit an error that looks
247
270
something like this `Error: Ready check failed: ERR operation not permitted`.
248
271
272
+
## backpressure
273
+
274
+
### stream
275
+
276
+
The client exposed the used [stream](https://nodejs.org/api/stream.html) in `client.stream` and if the stream or client had to [buffer](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback) the command in `client.should_buffer`.
277
+
In combination this can be used to implement backpressure by checking the buffer state before sending a command and listening to the stream [drain](https://nodejs.org/api/stream.html#stream_event_drain) event.
278
+
249
279
## client.end(flush)
250
280
251
281
Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
@@ -272,7 +302,7 @@ client.get("foo_rand000000000000", function (err, reply) {
272
302
});
273
303
```
274
304
275
-
`client.end()` without the flush parameter should not be used in production!
305
+
`client.end()` without the flush parameter should NOT be used in production!
0 commit comments