Comparing version 1.0.1 to 1.0.2
@@ -24,3 +24,6 @@ var events = require('events'); | ||
function IncompleteReadBuffer(message) { | ||
this.name = 'IncompleteReadBuffer'; | ||
Error.call(this); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
@@ -27,0 +30,0 @@ } |
@@ -503,26 +503,3 @@ var _ = require('lodash'); | ||
// Subscribe commands are special | ||
var isSubscribeCommand = _.includes(Command.FLAGS.ENTER_SUBSCRIBER_MODE, command.name); | ||
var isUnsubscribeCommand = !isSubscribeCommand && _.includes(Command.FLAGS.EXIT_SUBSCRIBER_MODE, command.name); | ||
if (isSubscribeCommand || isUnsubscribeCommand) { | ||
if (isSubscribeCommand && !this.condition.mode.subscriber) { | ||
this.condition.mode.subscriber = new SubscriptionSet(); | ||
} | ||
var channels = command.args; | ||
if (isUnsubscribeCommand && channels.length === 0) { | ||
channels = this.condition.mode.subscriber.channels(command.name); | ||
} | ||
command.remainReplies = channels.length; | ||
for (var i = 0; i < channels.length; ++i) { | ||
var channel = channels[i]; | ||
if (isSubscribeCommand) { | ||
this.condition.mode.subscriber.add(command.name, channel); | ||
} else { | ||
this.condition.mode.subscriber.del(command.name, channel); | ||
} | ||
this.subscriptionQueue.push(command.name, channel, command); | ||
} | ||
} else { | ||
this.commandQueue.push(command); | ||
} | ||
this.commandQueue.push(command); | ||
@@ -537,2 +514,3 @@ if (_.includes(Command.FLAGS.WILL_DISCONNECT, command.name)) { | ||
} | ||
} else if (this.options.enableOfflineQueue) { | ||
@@ -539,0 +517,0 @@ debug('queue command[%d] -> %s(%s)', this.condition.select, command.name, command.args); |
@@ -116,2 +116,3 @@ var Queue = require('fastqueue'); | ||
return function (error) { | ||
debug('error: %s', error); | ||
self.silentEmit('error', error); | ||
@@ -118,0 +119,0 @@ }; |
var _ = require('lodash'); | ||
var Queue = require('fastqueue'); | ||
var utils = require('../../utils'); | ||
var Command = require('../../command'); | ||
var SubscriptionSet = require('../../subscription_set'); | ||
var debug = require('debug')('ioredis:reply'); | ||
@@ -21,13 +24,7 @@ /** | ||
this.replyParser.on('reply error', function (reply) { | ||
process.nextTick(function () { | ||
self.returnError(reply); | ||
}); | ||
self.returnError(reply); | ||
}); | ||
this.replyParser.on('reply', function (reply) { | ||
// Prevent the exception be caught by the parser. | ||
process.nextTick(function () { | ||
self.returnReply(reply); | ||
}); | ||
self.returnReply(reply); | ||
}); | ||
// "error" is bad. Somehow the parser got confused. It'll try to reset and continue. | ||
this.replyParser.on('error', function (err) { | ||
@@ -74,11 +71,7 @@ self.emit('error', new Error('Redis reply parser error: ' + err.stack)); | ||
var associatedCommand = this.commandQueue.shift(); | ||
if (this.commandQueue.length === 0) { | ||
this.commandQueue = new Queue(); | ||
} | ||
var command, channel, count; | ||
if (this.condition.mode.subscriber) { | ||
var replyType = Array.isArray(reply) ? reply[0].toString() : null; | ||
debug('receive reply "%s" in subscriber mode', replyType); | ||
if (this.condition.mode.subscriber && !associatedCommand) { | ||
// If the reply is a message/pmessage, | ||
// then just emit it instead of considering it as a reply | ||
var replyType = Array.isArray(reply) ? reply[0].toString() : null; | ||
switch (replyType) { | ||
@@ -104,25 +97,86 @@ case 'message': | ||
case 'psubscribe': | ||
channel = reply[1].toString(); | ||
this.condition.mode.subscriber.add(replyType, channel); | ||
command = shiftCommand.call(this); | ||
if (!fillSubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
} | ||
break; | ||
case 'unsubscribe': | ||
case 'punsubscribe': | ||
var channel = reply[1].toString(); | ||
var count = reply[2]; | ||
channel = reply[1] ? reply[1].toString() : null; | ||
if (channel) { | ||
this.condition.mode.subscriber.del(replyType, channel); | ||
} | ||
count = reply[2]; | ||
if (count === 0) { | ||
this.condition.mode.subscriber = false; | ||
} | ||
var command = this.subscriptionQueue.shift(replyType, channel); | ||
if (command) { | ||
command.remainReplies -= 1; | ||
if (command.remainReplies === 0) { | ||
command.resolve(count); | ||
} | ||
command = shiftCommand.call(this); | ||
if (!fillUnsubCommand(command, count)) { | ||
this.commandQueue.unshift(command); | ||
} | ||
break; | ||
default: | ||
this.emit('error', new Error('Subscription queue state error. If you can reproduce this, please report it.')); | ||
command = shiftCommand.call(this); | ||
command.resolve(reply); | ||
} | ||
} else if (associatedCommand) { | ||
associatedCommand.resolve(reply); | ||
} else { | ||
this.emit('error', new Error('Command queue state error. If you can reproduce this, please report it.')); | ||
command = shiftCommand.call(this); | ||
if (!command) { | ||
return this.emit('error', new Error('Command queue state error. If you can reproduce this, please report it.')); | ||
} | ||
if (_.includes(Command.FLAGS.ENTER_SUBSCRIBER_MODE, command.name)) { | ||
this.condition.mode.subscriber = new SubscriptionSet(); | ||
this.condition.mode.subscriber.add(command.name, reply[1].toString()); | ||
if (!fillSubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
} | ||
} else if (_.includes(Command.FLAGS.EXIT_SUBSCRIBER_MODE, command.name)) { | ||
if (!fillUnsubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
} | ||
} else { | ||
command.resolve(reply); | ||
} | ||
} | ||
function shiftCommand() { | ||
var command = this.commandQueue.shift(); | ||
if (this.commandQueue.length === 0) { | ||
this.commandQueue = new Queue(); | ||
} | ||
return command; | ||
} | ||
function fillSubCommand(command, count) { | ||
if (typeof command.remainReplies === 'undefined') { | ||
command.remainReplies = command.args.length; | ||
} | ||
if (--command.remainReplies === 0) { | ||
command.resolve(reply[2]); | ||
return true; | ||
} | ||
return false; | ||
} | ||
function fillUnsubCommand(command, count) { | ||
if (typeof command.remainReplies === 'undefined') { | ||
command.remainReplies = command.args.length; | ||
} | ||
if (command.remainReplies === 0) { | ||
if (count === 0) { | ||
command.resolve(reply[2]); | ||
return true; | ||
} | ||
return false; | ||
} | ||
if (--command.remainReplies === 0) { | ||
command.resolve(reply[2]); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
}; |
@@ -26,2 +26,6 @@ /** | ||
SubscriptionSet.prototype.isEmpty = function () { | ||
return this.channels('subscribe').length === 0 && this.channels('psubscribe').length === 0; | ||
}; | ||
function mapSet(set) { | ||
@@ -28,0 +32,0 @@ if (set === 'unsubscribe') { |
{ | ||
"name": "ioredis", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A delightful, performance-focused Redis client for Node and io.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -239,3 +239,2 @@ # ioredis | ||
if (args.length === 2) { | ||
var pos = 1; | ||
if (typeof Map !== 'undefined' && args[1] instanceof Map) { | ||
@@ -367,3 +366,3 @@ return [args[0]].concat(utils.convertMapToArray(args[1])); | ||
the return value represents how long(ms) to wait to reconnect. When the | ||
return value isn't a number, ioredis will stop trying reconnect and the connection | ||
return value isn't a number, ioredis will stop trying reconnecting and the connection | ||
will be lost forever if user don't call `redis.connect()` manually. | ||
@@ -406,3 +405,3 @@ | ||
## Cluster | ||
Support for Cluster is currently experimental and under active development. It's not recommended to use it in production. | ||
Support for Cluster is currently experimental. It's not recommended to use it in production. | ||
If you encounter any problems, welcome to submit an issue :-). | ||
@@ -409,0 +408,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
166199
55
3836
3
499