diff --git a/lib/individualCommands.js b/lib/individualCommands.js index 885219b2a6..f83ca89fd0 100644 --- a/lib/individualCommands.js +++ b/lib/individualCommands.js @@ -103,7 +103,7 @@ Multi.prototype.quit = function quit () { this._client._closing = true this._client.ready = false } - this._queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite)) + this._queue.push(new Command('quit', [], callOnWrite, quitCallback(this._client))) return this } diff --git a/lib/multi.js b/lib/multi.js index f55986cd03..0ef9421256 100644 --- a/lib/multi.js +++ b/lib/multi.js @@ -91,7 +91,7 @@ function execTransaction (multi) { // Drain queue, callback will catch 'QUEUED' or error for (var index = 0; index < len; index++) { // The commands may not be shifted off, since they are needed in the result handler - promises.push(pipelineTransactionCommand(multi, queue.get(index), index).catch((e) => e)) + promises.push(pipelineTransactionCommand(multi, queue.peekAt(index), index).catch((e) => e)) } const main = client.internalSendCommand(new Command('exec', [])) @@ -130,7 +130,7 @@ function execBatch (multi) { return Promise.all(promises).then((res) => { if (error) { const err = new Errors.RedisError('bla failed') - err.code = 'foo' + err.code = 'ERR' err.replies = res return Promise.reject(err) } diff --git a/lib/pubsub.js b/lib/pubsub.js index 01eabc16e6..7aa897c599 100644 --- a/lib/pubsub.js +++ b/lib/pubsub.js @@ -11,7 +11,7 @@ const SUBSCRIBE_COMMANDS = { function subscribeUnsubscribe (client, reply, type) { // Subscribe commands take an optional callback and also emit an event, but only the Last_ response is included in the callback // The pub sub commands return each argument in a separate return value and have to be handled that way - const commandObj = client.commandQueue.get(0) + const commandObj = client.commandQueue.peekAt(0) const buffer = client._options.returnBuffers || client._options.detectBuffers && commandObj.bufferArgs const channel = (buffer || reply[1] === null) ? reply[1] : reply[1].toString() const count = +reply[2] // Return the channel counter as number no matter if `stringNumbers` is activated or not @@ -31,16 +31,14 @@ function subscribeUnsubscribe (client, reply, type) { if (commandObj.argsLength === 1 || client._subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) { if (count === 0) { // Unsubscribed from all channels - var runningCommand - var i = 1 client._pubSubMode = 0 // Deactivating pub sub mode // This should be a rare case and therefore handling it this way should be good performance wise for the general case - for (runningCommand = client.commandQueue.get(i); runningCommand !== undefined; runningCommand = client.commandQueue.get(i)) { + for (var i = 1; i < client.commandQueue.length; i++) { + const runningCommand = client.commandQueue.peekAt(i) if (SUBSCRIBE_COMMANDS[runningCommand.command]) { client._pubSubMode = i // Entering pub sub mode again break } - i++ } } client.commandQueue.shift() diff --git a/test/connection.spec.js b/test/connection.spec.js index 6a5d3c297b..192903f9dc 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -507,6 +507,15 @@ describe('connection tests', () => { assert(delayed) end() }) + // Cover info parts with no value + setImmediate(() => { + const command = client.commandQueue.peekAt(0) + const callback = command.callback + command.callback = (err, res) => { + res += 'added:\r\n' + callback(err, res) + } + }) }) it('redis still loading > 1000ms', (done) => {