1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

chore - remove standard and use individual config

Standard is not as up to date and still uses a old eslint version.
Instead, use the airbnb default with a couple of modifications.

All required changes are included.
This commit is contained in:
Ruben Bridgewater
2017-11-28 21:38:21 -02:00
parent 0206ecbf51
commit 2b4ab10305
97 changed files with 888 additions and 673 deletions

View File

@@ -4,6 +4,7 @@ const Queue = require('denque')
const Errors = require('redis-errors')
const Command = require('./command')
const utils = require('./utils')
const handleReply = utils.handleReply
/**
@@ -15,7 +16,7 @@ const handleReply = utils.handleReply
* @param {number} index Command index in the Multi queue
* @returns *
*/
function pipelineTransactionCommand (multi, command, index) {
function pipelineTransactionCommand(multi, command, index) {
// Queueing is done first, then the commands are executed
const tmp = command.callback
command.callback = function (err, reply) {
@@ -37,7 +38,7 @@ function pipelineTransactionCommand (multi, command, index) {
* @param {any[]} replies
* @returns any[]
*/
function multiCallback (multi, replies) {
function multiCallback(multi, replies) {
if (replies) {
var i = 0
const queue = multi._queue
@@ -70,13 +71,11 @@ function multiCallback (multi, replies) {
* @param {Multi} multi
* @returns Promise<any[]>
*/
function execTransaction (multi) {
function execTransaction(multi) {
const client = multi._client
const queue = multi._queue
if (multi._monitoring || client._monitoring) {
const err = new RangeError(
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
)
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 new Promise((resolve, reject) => {
@@ -89,16 +88,19 @@ function execTransaction (multi) {
// Silently ignore this error. We'll receive the error for the exec as well
const promises = [client.internalSendCommand(new Command('multi', [])).catch(() => {})]
// 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
promises.push(pipelineTransactionCommand(multi, queue.peekAt(index), index).catch((e) => e))
promises.push(pipelineTransactionCommand(multi, queue.peekAt(index), index).catch(e => e))
}
const main = client.internalSendCommand(new Command('exec', []))
return Promise.all(promises).then(() => main.then((replies) => multiCallback(multi, replies)).catch((err) => {
err.errors = multi._errors
return Promise.reject(err)
}))
return Promise.all(promises)
.then(() => main
.then(replies => multiCallback(multi, replies))
.catch((err) => {
err.errors = multi._errors
return Promise.reject(err)
}))
}
/**
@@ -107,7 +109,7 @@ function execTransaction (multi) {
* @param {Multi} multi
* @returns Promise<any[]>
*/
function execBatch (multi) {
function execBatch(multi) {
const client = multi._client
const queue = multi._queue
if (queue.length === 0) {
@@ -119,13 +121,14 @@ function execBatch (multi) {
})
}
var error = false
function setError(err) {
error = true
return err
}
const promises = []
while (queue.length) {
const command = queue.shift()
promises.push(client.internalSendCommand(command).catch((e) => {
error = true
return e
}))
promises.push(client.internalSendCommand(command).catch(setError))
}
return Promise.all(promises).then((res) => {
if (error) {
@@ -147,14 +150,14 @@ class Multi {
*
* @memberof Multi
*/
constructor (client, type, args) {
constructor(client, type, args) {
this._client = client
this._type = type
this._queue = new Queue()
// Either undefined or an array. Fail hard if it's not an array
if (args) {
// Legacy support for passing in an array of arguments
for (var i = 0; i < args.length; i++) {
for (let i = 0; i < args.length; i++) {
const command = args[i][0]
const tmpArgs = args[i].slice(1)
if (Array.isArray(command)) {
@@ -173,7 +176,7 @@ class Multi {
*
* @memberof Multi
*/
execAtomic () {
execAtomic() {
if (this._queue.length < 2) {
return this.execBatch()
}
@@ -187,7 +190,7 @@ class Multi {
*
* @memberof Multi
*/
exec () {
exec() {
if (this._type === 'batch') {
return execBatch(this)
}