Comparing version 1.3.5 to 1.3.6
@@ -5,2 +5,7 @@ ## Changelog | ||
### v1.3.6 - May 22, 2015 | ||
* Support Node.js 0.10.16 | ||
* Fix unfulfilled commands being sent to the wrong db.([#42](https://github.com/luin/ioredis/issues/42)). | ||
### v1.3.5 - May 21, 2015 | ||
@@ -7,0 +12,0 @@ |
@@ -244,17 +244,3 @@ 'use strict'; | ||
// very large packet | ||
// check for concat, if we have it, use it | ||
if (Buffer.concat !== undefined) { | ||
this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]); | ||
} else { | ||
var remaining = this._bytesRemaining(), | ||
newLength = remaining + newBuffer.length, | ||
tmpBuffer = new Buffer(newLength); | ||
this._buffer.copy(tmpBuffer, 0, this._offset); | ||
newBuffer.copy(tmpBuffer, remaining, 0); | ||
this._buffer = tmpBuffer; | ||
} | ||
this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]); | ||
this._offset = 0; | ||
@@ -291,6 +277,2 @@ }; | ||
ReplyParser.prototype.parser_error = function (message) { | ||
this.emit('error', message); | ||
}; | ||
ReplyParser.prototype.send_error = function (reply) { | ||
@@ -297,0 +279,0 @@ this.emit('reply error', reply); |
@@ -272,2 +272,7 @@ 'use strict'; | ||
} | ||
// Reset writePending for resending | ||
writePending = _this._queue.length; | ||
data = ''; | ||
bufferMode = false; | ||
} | ||
@@ -274,0 +279,0 @@ } |
@@ -322,6 +322,5 @@ 'use strict'; | ||
var command; | ||
while (this.commandQueue.length > 0) { | ||
command = this.commandQueue.shift(); | ||
command.reject(error); | ||
item = this.commandQueue.shift(); | ||
item.command.reject(error); | ||
} | ||
@@ -489,3 +488,7 @@ }; | ||
this.commandQueue.push(command); | ||
this.commandQueue.push({ | ||
command: command, | ||
stream: stream, | ||
select: this.condition.select | ||
}); | ||
@@ -492,0 +495,0 @@ if (_.includes(Command.FLAGS.WILL_DISCONNECT, command.name)) { |
@@ -102,8 +102,15 @@ 'use strict'; | ||
var item; | ||
var finalSelect = self.condition.select; | ||
self.condition.select = 0; | ||
if (self.prevCommandQueue) { | ||
if (self.options.autoResendUnfulfilledCommands) { | ||
debug('resend %d unfulfilled commands', self.prevCommandQueue.length); | ||
while (self.prevCommandQueue.length) { | ||
var command = self.prevCommandQueue.shift(); | ||
self.sendCommand(command); | ||
while (self.prevCommandQueue.length > 0) { | ||
item = self.prevCommandQueue.shift(); | ||
if (item.select !== self.condition.select && item.command.name !== 'select') { | ||
self.select(item.select); | ||
} | ||
self.sendCommand(item.command, item.stream); | ||
} | ||
@@ -115,4 +122,2 @@ } else { | ||
var finalSelect = self.condition.select; | ||
self.condition.select = 0; | ||
if (self.offlineQueue.length) { | ||
@@ -123,3 +128,3 @@ debug('send %d commands in offline queue', self.offlineQueue.length); | ||
while (offlineQueue.length > 0) { | ||
var item = offlineQueue.shift(); | ||
item = offlineQueue.shift(); | ||
if (item.select !== self.condition.select && item.command.name !== 'select') { | ||
@@ -131,2 +136,3 @@ self.select(item.select); | ||
} | ||
if (self.condition.select !== finalSelect) { | ||
@@ -133,0 +139,0 @@ debug('connect to db [%d]', finalSelect); |
@@ -35,3 +35,3 @@ 'use strict'; | ||
exports.returnError = function (err) { | ||
var command = this.commandQueue.shift(); | ||
var command = this.commandQueue.shift().command; | ||
@@ -72,3 +72,3 @@ err.command = { | ||
var command, channel, count; | ||
var item, channel, count; | ||
if (this.condition.mode.subscriber) { | ||
@@ -100,5 +100,5 @@ var replyType = Array.isArray(reply) ? reply[0].toString() : null; | ||
this.condition.mode.subscriber.add(replyType, channel); | ||
command = shiftCommand(this); | ||
if (!fillSubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
item = this.commandQueue.shift(); | ||
if (!fillSubCommand(item.command, reply[2])) { | ||
this.commandQueue.unshift(item); | ||
} | ||
@@ -116,37 +116,32 @@ break; | ||
} | ||
command = shiftCommand(this); | ||
if (!fillUnsubCommand(command, count)) { | ||
this.commandQueue.unshift(command); | ||
item = this.commandQueue.shift(); | ||
if (!fillUnsubCommand(item.command, count)) { | ||
this.commandQueue.unshift(item); | ||
} | ||
break; | ||
default: | ||
command = shiftCommand(this); | ||
command.resolve(reply); | ||
item = this.commandQueue.shift(); | ||
item.command.resolve(reply); | ||
} | ||
} else { | ||
command = shiftCommand(this); | ||
if (!command) { | ||
item = this.commandQueue.shift(); | ||
if (!item) { | ||
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)) { | ||
if (_.includes(Command.FLAGS.ENTER_SUBSCRIBER_MODE, item.command.name)) { | ||
this.condition.mode.subscriber = new SubscriptionSet(); | ||
this.condition.mode.subscriber.add(command.name, reply[1].toString()); | ||
this.condition.mode.subscriber.add(item.command.name, reply[1].toString()); | ||
if (!fillSubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
if (!fillSubCommand(item.command, reply[2])) { | ||
this.commandQueue.unshift(item); | ||
} | ||
} else if (_.includes(Command.FLAGS.EXIT_SUBSCRIBER_MODE, command.name)) { | ||
if (!fillUnsubCommand(command, reply[2])) { | ||
this.commandQueue.unshift(command); | ||
} else if (_.includes(Command.FLAGS.EXIT_SUBSCRIBER_MODE, item.command.name)) { | ||
if (!fillUnsubCommand(item.command, reply[2])) { | ||
this.commandQueue.unshift(item); | ||
} | ||
} else { | ||
command.resolve(reply); | ||
item.command.resolve(reply); | ||
} | ||
} | ||
function shiftCommand(self) { | ||
var command = self.commandQueue.shift(); | ||
return command; | ||
} | ||
function fillSubCommand(command, count) { | ||
@@ -153,0 +148,0 @@ if (typeof command.remainReplies === 'undefined') { |
{ | ||
"name": "ioredis", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "A delightful, performance-focused Redis client for Node and io.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,3 @@ # ioredis | ||
Support Redis >= 2.6.12 and (Node.js >= 0.11.16 or io.js). | ||
Support Redis >= 2.6.12 and (Node.js >= 0.10.16 or io.js). | ||
@@ -14,0 +14,0 @@ # Feature |
'use strict'; | ||
var utils = require('../../lib/utils'); | ||
var Promise = require('bluebird'); | ||
@@ -5,0 +6,0 @@ describe('cluster', function () { |
@@ -102,2 +102,10 @@ 'use strict'; | ||
}); | ||
it('should reject when connected', function (done) { | ||
var redis = new Redis(); | ||
redis.connect().catch(function (err) { | ||
expect(err.message).to.match(/Redis is already connecting/); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -136,17 +144,24 @@ | ||
describe('autoResendUnfulfilledCommands', function () { | ||
it('should resend unfulfilled when reconnected', function (done) { | ||
var redis = new Redis(); | ||
var pub = new Redis(); | ||
it('should resend unfulfilled commands to the correct db when reconnected', function (done) { | ||
var redis = new Redis({ db: 3 }); | ||
var pub = new Redis({ db: 3 }); | ||
redis.once('ready', function () { | ||
var write = redis.stream.write; | ||
redis.stream.write = function () { | ||
write.apply(redis.stream, arguments); | ||
redis.stream.write = write; | ||
redis.stream.end(); | ||
}; | ||
var pending = 2; | ||
redis.blpop('l', 0, function (err, res) { | ||
expect(res[0]).to.eql('l'); | ||
expect(res[1]).to.eql('1'); | ||
done(); | ||
if (!--pending) { | ||
done(); | ||
} | ||
}); | ||
redis.set('foo', '1'); | ||
redis.pipeline().incr('foo').exec(function (err, res) { | ||
expect(res[0][1]).to.eql(2); | ||
if (!--pending) { | ||
done(); | ||
} | ||
}); | ||
setTimeout(function () { | ||
redis.stream.end(); | ||
}, 0); | ||
}); | ||
@@ -153,0 +168,0 @@ redis.once('close', function () { |
@@ -102,2 +102,19 @@ 'use strict'; | ||
}); | ||
it('should reject when disconnected', function (done) { | ||
var redis = new Redis(); | ||
redis.disconnect(); | ||
redis.get('foo', function (err) { | ||
expect(err.message).to.match(/Connection is closed./); | ||
done(); | ||
}); | ||
}); | ||
it('should reject when enableOfflineQueue is disabled', function (done) { | ||
var redis = new Redis({ enableOfflineQueue: false }); | ||
redis.get('foo', function (err) { | ||
expect(err.message).to.match(/enableOfflineQueue options is false/); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -28,2 +28,11 @@ 'use strict'; | ||
it('should return bulk strings', function (done) { | ||
var parser = new Parser({ returnBuffers: true }); | ||
parser.on('reply', function (res) { | ||
expect(res.toString()).to.eql('OK'); | ||
done(); | ||
}); | ||
parser.execute(new Buffer('$2\r\nOK\r\n')); | ||
}); | ||
it('should support return string directly', function (done) { | ||
@@ -75,6 +84,9 @@ var parser = new Parser({ returnBuffers: false }); | ||
setTimeout(function () { | ||
parser.execute(new Buffer('\n*2\r\n:3\r\n$3\r\nbar\r\n')); | ||
}, 0); | ||
parser.execute(new Buffer('')); | ||
setTimeout(function () { | ||
parser.execute(new Buffer('\n*2\r\n:3\r\n$3\r\nbar\r\n')); | ||
}); | ||
}, 1); | ||
}); | ||
}); | ||
}); |
@@ -89,3 +89,28 @@ 'use strict'; | ||
}); | ||
it('should throw when arguments is invalid', function () { | ||
expect(function () { | ||
new Redis(function () {}); | ||
}).to.throw(Error); | ||
}); | ||
}); | ||
describe('.createClient', function () { | ||
it('should redirect to constructor', function () { | ||
var redis = Redis.createClient({ name: 'pass', lazyConnect: true }); | ||
expect(redis.options).to.have.property('name', 'pass'); | ||
expect(redis.options).to.have.property('lazyConnect', true); | ||
}); | ||
}); | ||
describe('#end', function () { | ||
it('should redirect to #disconnect', function (done) { | ||
var redis = new Redis({ lazyConnect: true }); | ||
stub(redis, 'disconnect', function () { | ||
redis.disconnect.restore(); | ||
done(); | ||
}); | ||
redis.end(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
262021
65
6978