You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
test fixup
This commit is contained in:
50
lib/multi.js
50
lib/multi.js
@@ -1,15 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
var Queue = require('double-ended-queue')
|
||||
var utils = require('./utils')
|
||||
var Command = require('./command')
|
||||
const Queue = require('double-ended-queue')
|
||||
const utils = require('./utils')
|
||||
const Command = require('./command')
|
||||
|
||||
function Multi (client, args) {
|
||||
this._client = client
|
||||
this.queue = new Queue()
|
||||
var command, tmpArgs
|
||||
let command, tmpArgs
|
||||
if (args) { // Either undefined or an array. Fail hard if it's not an array
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
command = args[i][0]
|
||||
tmpArgs = args[i].slice(1)
|
||||
if (Array.isArray(command)) {
|
||||
@@ -23,7 +23,7 @@ function Multi (client, args) {
|
||||
|
||||
function pipelineTransactionCommand (self, commandObj, index) {
|
||||
// Queueing is done first, then the commands are executed
|
||||
var tmp = commandObj.callback
|
||||
const tmp = commandObj.callback
|
||||
commandObj.callback = function (err, reply) {
|
||||
// Ignore the multi command. This is applied by nodeRedis and the user does not benefit by it
|
||||
if (err && index !== -1) {
|
||||
@@ -49,7 +49,7 @@ Multi.prototype.execAtomic = function execAtomic (callback) {
|
||||
}
|
||||
|
||||
function multiCallback (self, err, replies) {
|
||||
var i = 0
|
||||
let i = 0
|
||||
|
||||
if (err) {
|
||||
err.errors = self.errors
|
||||
@@ -63,9 +63,9 @@ function multiCallback (self, err, replies) {
|
||||
}
|
||||
|
||||
if (replies) {
|
||||
for (var commandObj = self.queue.shift(); commandObj !== undefined; commandObj = self.queue.shift()) {
|
||||
for (let commandObj = self.queue.shift(); commandObj !== undefined; commandObj = self.queue.shift()) {
|
||||
if (replies[i] instanceof Error) {
|
||||
var match = replies[i].message.match(utils.errCode)
|
||||
const match = replies[i].message.match(utils.errCode)
|
||||
// LUA script could return user errors that don't behave like all other errors!
|
||||
if (match) {
|
||||
replies[i].code = match[1]
|
||||
@@ -92,31 +92,31 @@ function multiCallback (self, err, replies) {
|
||||
|
||||
Multi.prototype.execTransaction = function execTransaction (callback) {
|
||||
if (this.monitoring || this._client.monitoring) {
|
||||
var err = new RangeError(
|
||||
const err = new RangeError(
|
||||
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
|
||||
)
|
||||
err.command = 'EXEC'
|
||||
err.code = 'EXECABORT'
|
||||
return utils.replyInOrder(this._client, callback, err)
|
||||
}
|
||||
var self = this
|
||||
var len = self.queue.length
|
||||
const self = this
|
||||
const len = self.queue.length
|
||||
self.errors = []
|
||||
self.callback = callback
|
||||
self._client.cork()
|
||||
self.wantsBuffers = new Array(len)
|
||||
pipelineTransactionCommand(self, new Command('multi', []), -1)
|
||||
// Drain queue, callback will catch 'QUEUED' or error
|
||||
for (var index = 0; index < len; index++) {
|
||||
for (let index = 0; index < len; index++) {
|
||||
// The commands may not be shifted off, since they are needed in the result handler
|
||||
pipelineTransactionCommand(self, self.queue.get(index), index)
|
||||
}
|
||||
|
||||
self._client.internalSendCommand(new Command('exec', [], function (err, replies) {
|
||||
self._client.internalSendCommand(new Command('exec', [], (err, replies) => {
|
||||
multiCallback(self, err, replies)
|
||||
}))
|
||||
self._client.uncork()
|
||||
return !self._client.shouldBuffer
|
||||
return
|
||||
}
|
||||
|
||||
function batchCallback (self, cb, i) {
|
||||
@@ -133,13 +133,13 @@ function batchCallback (self, cb, i) {
|
||||
}
|
||||
|
||||
Multi.prototype.exec = Multi.prototype.execBatch = function execBatch (callback) {
|
||||
var self = this
|
||||
var len = self.queue.length
|
||||
var index = 0
|
||||
var commandObj
|
||||
const self = this
|
||||
const len = self.queue.length
|
||||
let index = 0
|
||||
let commandObj
|
||||
if (len === 0) {
|
||||
utils.replyInOrder(self._client, callback, null, [])
|
||||
return !self._client.shouldBuffer
|
||||
return
|
||||
}
|
||||
self._client.cork()
|
||||
if (!callback) {
|
||||
@@ -147,13 +147,13 @@ Multi.prototype.exec = Multi.prototype.execBatch = function execBatch (callback)
|
||||
self._client.internalSendCommand(commandObj)
|
||||
}
|
||||
self._client.uncork()
|
||||
return !self._client.shouldBuffer
|
||||
return
|
||||
}
|
||||
var callbackWithoutOwnCb = function (err, res) {
|
||||
const callbackWithoutOwnCb = function (err, res) {
|
||||
if (err) {
|
||||
self.results.push(err)
|
||||
// Add the position to the error
|
||||
var i = self.results.length - 1
|
||||
const i = self.results.length - 1
|
||||
self.results[i].position = i
|
||||
} else {
|
||||
self.results.push(res)
|
||||
@@ -161,7 +161,7 @@ Multi.prototype.exec = Multi.prototype.execBatch = function execBatch (callback)
|
||||
// Do not emit an error here. Otherwise each error would result in one emit.
|
||||
// The errors will be returned in the result anyway
|
||||
}
|
||||
var lastCallback = function (cb) {
|
||||
const lastCallback = function (cb) {
|
||||
return function (err, res) {
|
||||
cb(err, res)
|
||||
callback(null, self.results)
|
||||
@@ -181,7 +181,7 @@ Multi.prototype.exec = Multi.prototype.execBatch = function execBatch (callback)
|
||||
index++
|
||||
}
|
||||
self._client.uncork()
|
||||
return !self._client.shouldBuffer
|
||||
return
|
||||
}
|
||||
|
||||
module.exports = Multi
|
||||
|
Reference in New Issue
Block a user