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

chore: use arrow functions

This commit is contained in:
Ruben Bridgewater
2017-05-26 10:37:38 +02:00
parent 55fb67adaf
commit 54671f6c52
5 changed files with 84 additions and 125 deletions

View File

@@ -49,13 +49,12 @@ Multi.prototype.select = function select (db) {
return this
}
RedisClient.prototype.monitor = RedisClient.prototype.MONITOR = function monitor () {
RedisClient.prototype.monitor = function monitor () {
// Use a individual command, as this is a special case that does not has to be checked for any other command
const self = this
const callOnWrite = function () {
const callOnWrite = () => {
// 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
this.monitoring = true
}
return this.internalSendCommand(new Command('monitor', [], callOnWrite))
}
@@ -64,9 +63,8 @@ RedisClient.prototype.monitor = RedisClient.prototype.MONITOR = function monitor
Multi.prototype.monitor = function monitor () {
// 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) {
const self = this
const callOnWrite = function () {
self._client.monitoring = true
const callOnWrite = () => {
this._client.monitoring = true
}
this.queue.push(new Command('monitor', [], callOnWrite))
return this
@@ -108,13 +106,12 @@ RedisClient.prototype.quit = function quit () {
// Only works with batch, not in a transaction
Multi.prototype.quit = function quit () {
const self = this._client
const callOnWrite = function () {
const callOnWrite = () => {
// If called in a multi context, we expect redis is available
self.closing = true
self.ready = false
this._client.closing = true
this._client.ready = false
}
this.queue.push(new Command('quit', [], null, quitCallback(self), callOnWrite))
this.queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite))
return this
}
@@ -209,15 +206,14 @@ RedisClient.prototype.client = function client () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this
var 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') {
const replyOnOff = arr[1].toString().toUpperCase()
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
callOnWrite = function () {
self.reply = replyOnOff
callOnWrite = () => {
this.reply = replyOnOff
}
}
}
@@ -225,34 +221,19 @@ RedisClient.prototype.client = function client () {
}
Multi.prototype.client = function client () {
var arr
var len = arguments.length
var i = 0
if (Array.isArray(arguments[0])) {
arr = arguments[0]
} else if (Array.isArray(arguments[1])) {
len = arguments[1].length
arr = new Array(len + 1)
arr[0] = arguments[0]
for (; i < len; i += 1) {
arr[i + 1] = arguments[1][i]
}
} else {
len = arguments.length
arr = new Array(len)
for (; i < len; i += 1) {
arr[i] = arguments[i]
}
const len = arguments.length
const arr = new Array(len)
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this._client
var 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') {
const replyOnOff = arr[1].toString().toUpperCase()
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
callOnWrite = function () {
self.reply = replyOnOff
callOnWrite = () => {
this._client.reply = replyOnOff
}
}
}
@@ -266,9 +247,8 @@ RedisClient.prototype.subscribe = function subscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
const callOnWrite = () => {
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
}
return this.internalSendCommand(new Command('subscribe', arr, callOnWrite))
}
@@ -279,9 +259,8 @@ Multi.prototype.subscribe = function subscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this._client
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
const callOnWrite = () => {
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
}
this.queue.push(new Command('subscribe', arr, callOnWrite))
return this
@@ -293,10 +272,9 @@ RedisClient.prototype.unsubscribe = function unsubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this
const callOnWrite = function () {
const callOnWrite = () => {
// 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
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
}
return this.internalSendCommand(new Command('unsubscribe', arr, callOnWrite))
}
@@ -307,10 +285,9 @@ Multi.prototype.unsubscribe = function unsubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this._client
const callOnWrite = function () {
const callOnWrite = () => {
// 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
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
}
this.queue.push(new Command('unsubscribe', arr, callOnWrite))
return this
@@ -322,9 +299,8 @@ RedisClient.prototype.psubscribe = function psubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
const callOnWrite = () => {
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
}
return this.internalSendCommand(new Command('psubscribe', arr, callOnWrite))
}
@@ -335,9 +311,8 @@ Multi.prototype.psubscribe = function psubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this._client
const callOnWrite = function () {
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1
const callOnWrite = () => {
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
}
this.queue.push(new Command('psubscribe', arr, callOnWrite))
return this
@@ -349,10 +324,9 @@ RedisClient.prototype.punsubscribe = function punsubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this
const callOnWrite = function () {
const callOnWrite = () => {
// 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
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
}
return this.internalSendCommand(new Command('punsubscribe', arr, callOnWrite))
}
@@ -363,10 +337,9 @@ Multi.prototype.punsubscribe = function punsubscribe () {
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const self = this._client
const callOnWrite = function () {
const callOnWrite = () => {
// 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
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
}
this.queue.push(new Command('punsubscribe', arr, callOnWrite))
return this