-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from luin/try-again
feat(cluster): redirect on TRYAGAIN error
- Loading branch information
Showing
8 changed files
with
138 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
var Deque = require('double-ended-queue'); | ||
var debug = require('debug')('ioredis:delayqueue'); | ||
|
||
function DelayQueue() { | ||
this.queues = {}; | ||
this.timeouts = {}; | ||
} | ||
|
||
DelayQueue.prototype.push = function (bucket, item, options) { | ||
var callback = options.callback || process.nextTick; | ||
if (!this.queues[bucket]) { | ||
this.queues[bucket] = new Deque(); | ||
} | ||
|
||
var queue = this.queues[bucket]; | ||
queue.push(item); | ||
|
||
if (!this.timeouts[bucket]) { | ||
var _this = this; | ||
this.timeouts[bucket] = setTimeout(function () { | ||
callback(function () { | ||
_this.timeouts[bucket] = null; | ||
_this._execute(bucket); | ||
}); | ||
}, options.timeout); | ||
} | ||
}; | ||
|
||
DelayQueue.prototype._execute = function (bucket) { | ||
var queue = this.queues[bucket]; | ||
if (!queue) { | ||
return; | ||
} | ||
var length = queue.length; | ||
if (!length) { | ||
return; | ||
} | ||
debug('send %d commands in %s queue', length, bucket); | ||
|
||
this.queues[bucket] = null; | ||
while (queue.length > 0) { | ||
queue.shift()(); | ||
} | ||
}; | ||
|
||
module.exports = DelayQueue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters