Skip to content

Commit d9c815d

Browse files
author
Ruben Bridgewater
committed
Add retry_unfullfilled_commands option
1 parent a4285c1 commit d9c815d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,13 @@ RedisClient.prototype.connection_gone = function (why) {
490490
return;
491491
}
492492

493-
// Flush all commands that have not yet returned. We can't handle them appropriatly
494-
if (this.command_queue.length !== 0) {
493+
// Retry commands after a reconnect instead of throwing an error. Use this with caution
494+
if (this.options.retry_unfulfilled_commands) {
495+
this.offline_queue.unshift.apply(this.offline_queue, this.command_queue.toArray());
496+
this.command_queue.clear();
497+
} else if (this.command_queue.length !== 0) {
495498
error = new Error('Redis connection lost and command aborted in uncertain state. It might have been processed.');
496499
error.code = 'UNCERTAIN_STATE';
497-
// TODO: Evaluate to add this
498-
// if (this.options.retry_commands) {
499-
// this.offline_queue.unshift(this.command_queue.toArray());
500-
// error.message = 'Command aborted in uncertain state and queued for next connection.';
501-
// }
502500
this.flush_and_error(error, ['command_queue']);
503501
error.message = 'Redis connection lost and commands aborted in uncertain state. They might have been processed.';
504502
this.emit('error', error);

0 commit comments

Comments
 (0)