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

@@ -11,8 +11,9 @@ const Multi = require('./multi')
const offlineCommand = require('./offlineCommand')
const utils = require('./utils')
const normalizeAndWriteCommand = require('./writeCommand')
const noop = function () {}
var connectionId = 0
let connectionId = 0
// Attention: The second parameter might be removed at will and is not officially supported.
// Do not rely on this
@@ -23,15 +24,17 @@ class RedisClient extends EventEmitter {
*
* @memberof RedisClient
*/
constructor (options) {
constructor(options) {
var i
super()
// Copy the options so they are not mutated
options = utils.clone(options)
// TODO: Add a more restrictive options validation
const cnxOptions = {}
for (const tlsOption in options.tls) {
/* istanbul ignore else */
if (options.tls.hasOwnProperty(tlsOption)) {
if (options.tls) {
const tlsKeys = Object.keys(options.tls)
for (i = 0; i < tlsKeys.length; i++) {
const tlsOption = tlsKeys[i]
cnxOptions[tlsOption] = options.tls[tlsOption]
// Copy the tls options into the general options to make sure the address is set right
if (tlsOption === 'port' || tlsOption === 'host' || tlsOption === 'path' || tlsOption === 'family') {
@@ -40,8 +43,10 @@ class RedisClient extends EventEmitter {
}
}
if (options.stream) {
// The stream from the outside is used so no connection from this side is triggered but from the server this client should talk to
// Reconnect etc won't work with this. This requires monkey patching to work, so it is not officially supported
// The stream from the outside is used so no connection from this side is
// triggered but from the server this client should talk to Reconnect etc
// won't work with this. This requires monkey patching to work, so it is
// not officially supported
this.address = '"Private stream"'
} else if (options.path) {
cnxOptions.path = options.path
@@ -56,9 +61,10 @@ class RedisClient extends EventEmitter {
if (options.socketKeepalive === undefined) {
options.socketKeepalive = true
}
for (const command in options.renameCommands) {
/* istanbul ignore else */
if (options.renameCommands.hasOwnProperty(command)) {
if (options.renameCommands) {
const renameKeys = Object.keys(options.renameCommands)
for (i = 0; i < renameKeys.length; i++) {
const command = renameKeys[i]
options.renameCommands[command.toLowerCase()] = options.renameCommands[command]
}
}
@@ -116,7 +122,8 @@ class RedisClient extends EventEmitter {
this._closing = false
this._timesConnected = 0
this._connectionOptions = cnxOptions
// Only used as timeout until redis has to be connected to redis until throwing an connection error
// Only used as timeout until redis has to be connected to redis until
// throwing an connection error
this._connectTimeout = +options.connectTimeout || 60 * 1000 // ms
this._retryStrategy = options.retryStrategy || function (options) {
// TODO: Find better defaults
@@ -140,12 +147,15 @@ class RedisClient extends EventEmitter {
})
}
// Do not call internalSendCommand directly, if you are not absolutely certain it handles everything properly
// e.g. monitor / info does not work with internalSendCommand only
// Do not call internalSendCommand directly, if you are not absolutely certain
// it handles everything properly e.g. monitor / info does not work with
// internalSendCommand only
//
// TODO: Move this function out of the client as a private function
// TODO: Check how others can intercept (monkey patch) essential parts (e.g. opbeat)
// after making this private.
internalSendCommand (commandObj) {
//
// TODO: Check how others can intercept (monkey patch) essential parts (e.g.
// opbeat) after making this private.
internalSendCommand(commandObj) {
if (this.ready === false || this._stream.writable === false) {
// Handle offline commands right away
offlineCommand(this, commandObj)
@@ -175,7 +185,7 @@ class RedisClient extends EventEmitter {
}
// Redirect calls to the appropriate function and use to send arbitrary / not supported commands
sendCommand (command, args) {
sendCommand(command, args) {
// Throw to fail early instead of relying in order in this case
if (typeof command !== 'string') {
throw new TypeError(`Wrong input type "${command !== null && command !== undefined ? command.constructor.name : command}" for command name`)
@@ -188,11 +198,12 @@ class RedisClient extends EventEmitter {
}
}
// Using the raw multi command is only possible with this function
// If the command is not yet added to the client, the internal function should be called right away
// Otherwise we need to redirect the calls to make sure the internal functions don't get skipped
// The internal functions could actually be used for any non hooked function
// but this might change from time to time and at the moment there's no good way to distinguish them
// Using the raw multi command is only possible with this function If the
// command is not yet added to the client, the internal function should be
// called right away Otherwise we need to redirect the calls to make sure
// the internal functions don't get skipped The internal functions could
// actually be used for any non hooked function but this might change from
// time to time and at the moment there's no good way to distinguish them
// from each other, so let's just do it do it this way for the time being
if (command === 'multi' || typeof this[command] !== 'function') {
return this.internalSendCommand(new Command(command, args))
@@ -200,7 +211,7 @@ class RedisClient extends EventEmitter {
return this[command].apply(this, args)
}
end (flush) {
end(flush) {
if (typeof flush !== 'boolean') {
throw new TypeError('You must call "end" with the flush argument.')
}
@@ -222,7 +233,7 @@ class RedisClient extends EventEmitter {
return this._stream.destroySoon()
}
unref () {
unref() {
if (this.connected) {
debug('Unref\'ing the socket connection')
this._stream.unref()
@@ -237,18 +248,16 @@ class RedisClient extends EventEmitter {
// This would be another BC and it should be fine to return the client sync.
// Therefore a option could be to accept a resolved promise instead of a callback
// to return a promise.
duplicate (options, callback) {
duplicate(options, callback) {
if (typeof options === 'function') {
callback = options
options = null
}
const existingOptions = utils.clone(this._options)
options = utils.clone(options)
for (const elem in options) {
/* istanbul ignore else */
if (options.hasOwnProperty(elem)) {
existingOptions[elem] = options[elem]
}
const keys = Object.keys(options)
for (var i = 0; i < keys.length; i++) {
existingOptions[keys[i]] = options[keys[i]]
}
const client = new RedisClient(existingOptions)
// Return to the same state as the other client
@@ -274,14 +283,13 @@ class RedisClient extends EventEmitter {
}
// Note: this overrides a native function!
multi (args) {
multi(args) {
return new Multi(this, 'multi', args)
}
batch (args) {
batch(args) {
return new Multi(this, 'batch', args)
}
}
module.exports = RedisClient