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

test fixup

This commit is contained in:
Ruben Bridgewater
2017-05-06 08:16:19 +02:00
parent f1a7bcd735
commit b2613b2270
106 changed files with 2900 additions and 2967 deletions

View File

@@ -1,12 +1,12 @@
'use strict'
var utils = require('./utils')
var debug = require('./debug')
var Multi = require('./multi')
var Command = require('./command')
var noPasswordIsSet = /no password is set/
var loading = /LOADING/
var RedisClient = require('../').RedisClient
const utils = require('./utils')
const debug = require('./debug')
const Multi = require('./multi')
const Command = require('./command')
const noPasswordIsSet = /no password is set/
const loading = /LOADING/
const RedisClient = require('../').RedisClient
/********************************************************************************************
Replace built-in redis functions
@@ -22,7 +22,7 @@ var RedisClient = require('../').RedisClient
********************************************************************************************/
RedisClient.prototype.multi = function multi (args) {
var multi = new Multi(this, args)
const multi = new Multi(this, args)
multi.exec = multi.EXEC = multi.execTransaction
return multi
}
@@ -53,8 +53,8 @@ Multi.prototype.select = function select (db, callback) {
RedisClient.prototype.monitor = RedisClient.prototype.MONITOR = function monitor (callback) {
// Use a individual command, as this is a special case that does not has to be checked for any other command
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
// Activating monitor mode has to happen before Redis returned the callback. The monitor result is returned first.
// Therefore we expect the command to be properly processed. If this is not the case, it's not an issue either.
self.monitoring = true
@@ -66,8 +66,8 @@ RedisClient.prototype.monitor = RedisClient.prototype.MONITOR = function monitor
Multi.prototype.monitor = function monitor (callback) {
// Use a individual command, as this is a special case that does not has to be checked for any other command
if (this.exec !== this.execTransaction) {
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
self._client.monitoring = true
}
this.queue.push(new Command('monitor', [], callback, callOnWrite))
@@ -102,7 +102,7 @@ RedisClient.prototype.quit = function quit (callback) {
// TODO: Consider this for v.3
// Allow the quit command to be fired as soon as possible to prevent it landing in the offline queue.
// this.ready = this.offlineQueue.length === 0;
var backpressureIndicator = this.internalSendCommand(new Command('quit', [], quitCallback(this, callback)))
const backpressureIndicator = this.internalSendCommand(new Command('quit', [], quitCallback(this, callback)))
// Calling quit should always end the connection, no matter if there's a connection or not
this.closing = true
this.ready = false
@@ -111,8 +111,8 @@ RedisClient.prototype.quit = function quit (callback) {
// Only works with batch, not in a transaction
Multi.prototype.quit = function quit (callback) {
var self = this._client
var callOnWrite = function () {
const self = this._client
const callOnWrite = function () {
// If called in a multi context, we expect redis is available
self.closing = true
self.ready = false
@@ -124,11 +124,11 @@ Multi.prototype.quit = function quit (callback) {
function infoCallback (self, callback) {
return function (err, res) {
if (res) {
var obj = {}
var lines = res.toString().split('\r\n')
var line, parts, subParts
const obj = {}
const lines = res.toString().split('\r\n')
let line, parts, subParts
for (var i = 0; i < lines.length; i++) {
for (let i = 0; i < lines.length; i++) {
parts = lines[i].split(':')
if (parts[1]) {
if (parts[0].indexOf('db') === 0) {
@@ -145,7 +145,7 @@ function infoCallback (self, callback) {
}
obj.versions = []
if (obj.redis_version) {
obj.redis_version.split('.').forEach(function (num) {
obj.redis_version.split('.').forEach((num) => {
obj.versions.push(+num)
})
}
@@ -160,7 +160,7 @@ function infoCallback (self, callback) {
// Store info in this.serverInfo after each call
RedisClient.prototype.info = function info (section, callback) {
var args = []
let args = []
if (typeof section === 'function') {
callback = section
} else if (section !== undefined) {
@@ -170,7 +170,7 @@ RedisClient.prototype.info = function info (section, callback) {
}
Multi.prototype.info = function info (section, callback) {
var args = []
let args = []
if (typeof section === 'function') {
callback = section
} else if (section !== undefined) {
@@ -190,7 +190,7 @@ function authCallback (self, pass, callback) {
} else if (loading.test(err.message)) {
// If redis is still loading the db, it will not authenticate and everything else will fail
debug('Redis still loading, trying to authenticate later')
setTimeout(function () {
setTimeout(() => {
self.auth(pass, callback)
}, 100)
return
@@ -201,20 +201,20 @@ function authCallback (self, pass, callback) {
}
RedisClient.prototype.auth = function auth (pass, callback) {
debug('Sending auth to ' + this.address + ' id ' + this.connectionId)
debug(`Sending auth to ${this.address} id ${this.connectionId}`)
// Stash auth for connect and reconnect.
this.authPass = pass
var ready = this.ready
const ready = this.ready
this.ready = ready || this.offlineQueue.length === 0
var tmp = this.internalSendCommand(new Command('auth', [pass], authCallback(this, pass, callback)))
const tmp = this.internalSendCommand(new Command('auth', [pass], authCallback(this, pass, callback)))
this.ready = ready
return tmp
}
// Only works with batch, not in a transaction
Multi.prototype.auth = function auth (pass, callback) {
debug('Sending auth to ' + this.address + ' id ' + this.connectionId)
debug(`Sending auth to ${this.address} id ${this.connectionId}`)
// Stash auth for connect and reconnect.
this.authPass = pass
@@ -223,10 +223,10 @@ Multi.prototype.auth = function auth (pass, callback) {
}
RedisClient.prototype.client = function client () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0]
callback = arguments[1]
@@ -252,12 +252,12 @@ RedisClient.prototype.client = function client () {
arr[i] = arguments[i]
}
}
var self = this
var callOnWrite
const self = this
let callOnWrite
// CLIENT REPLY ON|OFF|SKIP
/* istanbul ignore next: TODO: Remove this as soon as Travis runs Redis 3.2 */
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
var replyOnOff = arr[1].toString().toUpperCase()
const replyOnOff = arr[1].toString().toUpperCase()
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
callOnWrite = function () {
self.reply = replyOnOff
@@ -268,10 +268,10 @@ RedisClient.prototype.client = function client () {
}
Multi.prototype.client = function client () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0]
callback = arguments[1]
@@ -297,12 +297,12 @@ Multi.prototype.client = function client () {
arr[i] = arguments[i]
}
}
var self = this._client
var callOnWrite
const self = this._client
let callOnWrite
// CLIENT REPLY ON|OFF|SKIP
/* istanbul ignore next: TODO: Remove this as soon as Travis runs Redis 3.2 */
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
var replyOnOff = arr[1].toString().toUpperCase()
const replyOnOff = arr[1].toString().toUpperCase()
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
callOnWrite = function () {
self.reply = replyOnOff
@@ -314,10 +314,10 @@ Multi.prototype.client = function client () {
}
RedisClient.prototype.hmset = function hmset () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0]
callback = arguments[1]
@@ -333,7 +333,7 @@ RedisClient.prototype.hmset = function hmset () {
}
} else if (typeof arguments[1] === 'object' && (arguments.length === 2 || (arguments.length === 3 && (typeof arguments[2] === 'function' || typeof arguments[2] === 'undefined')))) {
arr = [arguments[0]]
for (var field in arguments[1]) {
for (const field in arguments[1]) {
arr.push(field, arguments[1][field])
}
callback = arguments[2]
@@ -353,10 +353,10 @@ RedisClient.prototype.hmset = function hmset () {
}
Multi.prototype.hmset = function hmset () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0]
callback = arguments[1]
@@ -372,7 +372,7 @@ Multi.prototype.hmset = function hmset () {
}
} else if (typeof arguments[1] === 'object' && (arguments.length === 2 || (arguments.length === 3 && (typeof arguments[2] === 'function' || typeof arguments[2] === 'undefined')))) {
arr = [arguments[0]]
for (var field in arguments[1]) {
for (const field in arguments[1]) {
arr.push(field, arguments[1][field])
}
callback = arguments[2]
@@ -393,10 +393,10 @@ Multi.prototype.hmset = function hmset () {
}
RedisClient.prototype.subscribe = function subscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -412,18 +412,18 @@ RedisClient.prototype.subscribe = function subscribe () {
arr[i] = arguments[i]
}
}
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
return this.internalSendCommand(new Command('subscribe', arr, callback, callOnWrite))
}
Multi.prototype.subscribe = function subscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -439,8 +439,8 @@ Multi.prototype.subscribe = function subscribe () {
arr[i] = arguments[i]
}
}
var self = this._client
var callOnWrite = function () {
const self = this._client
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
this.queue.push(new Command('subscribe', arr, callback, callOnWrite))
@@ -448,10 +448,10 @@ Multi.prototype.subscribe = function subscribe () {
}
RedisClient.prototype.unsubscribe = function unsubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -467,8 +467,8 @@ RedisClient.prototype.unsubscribe = function unsubscribe () {
arr[i] = arguments[i]
}
}
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
@@ -476,10 +476,10 @@ RedisClient.prototype.unsubscribe = function unsubscribe () {
}
Multi.prototype.unsubscribe = function unsubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -495,8 +495,8 @@ Multi.prototype.unsubscribe = function unsubscribe () {
arr[i] = arguments[i]
}
}
var self = this._client
var callOnWrite = function () {
const self = this._client
const callOnWrite = function () {
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
@@ -505,10 +505,10 @@ Multi.prototype.unsubscribe = function unsubscribe () {
}
RedisClient.prototype.psubscribe = function psubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -524,18 +524,18 @@ RedisClient.prototype.psubscribe = function psubscribe () {
arr[i] = arguments[i]
}
}
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
return this.internalSendCommand(new Command('psubscribe', arr, callback, callOnWrite))
}
Multi.prototype.psubscribe = function psubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -551,8 +551,8 @@ Multi.prototype.psubscribe = function psubscribe () {
arr[i] = arguments[i]
}
}
var self = this._client
var callOnWrite = function () {
const self = this._client
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
this.queue.push(new Command('psubscribe', arr, callback, callOnWrite))
@@ -560,10 +560,10 @@ Multi.prototype.psubscribe = function psubscribe () {
}
RedisClient.prototype.punsubscribe = function punsubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -579,8 +579,8 @@ RedisClient.prototype.punsubscribe = function punsubscribe () {
arr[i] = arguments[i]
}
}
var self = this
var callOnWrite = function () {
const self = this
const callOnWrite = function () {
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}
@@ -588,10 +588,10 @@ RedisClient.prototype.punsubscribe = function punsubscribe () {
}
Multi.prototype.punsubscribe = function punsubscribe () {
var arr
var len = arguments.length
var callback
var i = 0
let arr
let len = arguments.length
let callback
let i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0].slice(0)
callback = arguments[1]
@@ -607,8 +607,8 @@ Multi.prototype.punsubscribe = function punsubscribe () {
arr[i] = arguments[i]
}
}
var self = this._client
var callOnWrite = function () {
const self = this._client
const callOnWrite = function () {
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
}