You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
chore: mark private variables as such and remove obsolete ones
This commit is contained in:
@@ -17,6 +17,9 @@ It will not restore the support for old Node.js versions, the return value of
|
|||||||
connectTimeout behavior. It will also only partially restore snake_case support
|
connectTimeout behavior. It will also only partially restore snake_case support
|
||||||
and maybe more.
|
and maybe more.
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
- Fixed auth in batch not saving the password
|
||||||
|
|
||||||
Features
|
Features
|
||||||
- Native promise support
|
- Native promise support
|
||||||
- Auto pipelining
|
- Auto pipelining
|
||||||
|
76
index.js
76
index.js
@@ -59,9 +59,16 @@ class RedisClient extends EventEmitter {
|
|||||||
this.address = `${cnxOptions.host}:${cnxOptions.port}`
|
this.address = `${cnxOptions.host}:${cnxOptions.port}`
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connectionOptions = cnxOptions
|
// Public Variables
|
||||||
this.connectionId = RedisClient.connectionId++
|
|
||||||
this.connected = false
|
this.connected = false
|
||||||
|
this.shouldBuffer = false
|
||||||
|
this.commandQueue = new Queue() // Holds sent commands to de-pipeline them
|
||||||
|
this.offlineQueue = new Queue() // Holds commands issued but not able to be sent
|
||||||
|
this.serverInfo = {}
|
||||||
|
|
||||||
|
// Private Variables
|
||||||
|
this._connectionOptions = cnxOptions
|
||||||
|
this.connectionId = RedisClient.connectionId++
|
||||||
if (options.socketKeepalive === undefined) {
|
if (options.socketKeepalive === undefined) {
|
||||||
options.socketKeepalive = true
|
options.socketKeepalive = true
|
||||||
}
|
}
|
||||||
@@ -72,6 +79,14 @@ class RedisClient extends EventEmitter {
|
|||||||
}
|
}
|
||||||
options.returnBuffers = !!options.returnBuffers
|
options.returnBuffers = !!options.returnBuffers
|
||||||
options.detectBuffers = !!options.detectBuffers
|
options.detectBuffers = !!options.detectBuffers
|
||||||
|
if (typeof options.enableOfflineQueue !== 'boolean') {
|
||||||
|
if (options.enableOfflineQueue !== undefined) {
|
||||||
|
throw new TypeError('enableOfflineQueue must be a boolean')
|
||||||
|
}
|
||||||
|
options.enableOfflineQueue = true
|
||||||
|
}
|
||||||
|
// Only used as timeout until redis has to be connected to redis until throwing an connection error
|
||||||
|
options.connectTimeout = +options.connectTimeout || 60000 // 60 * 1000 ms
|
||||||
// Override the detectBuffers setting if returnBuffers is active and print a warning
|
// Override the detectBuffers setting if returnBuffers is active and print a warning
|
||||||
if (options.returnBuffers && options.detectBuffers) {
|
if (options.returnBuffers && options.detectBuffers) {
|
||||||
process.nextTick(
|
process.nextTick(
|
||||||
@@ -81,31 +96,27 @@ class RedisClient extends EventEmitter {
|
|||||||
)
|
)
|
||||||
options.detectBuffers = false
|
options.detectBuffers = false
|
||||||
}
|
}
|
||||||
this.shouldBuffer = false
|
|
||||||
this.commandQueue = new Queue() // Holds sent commands to de-pipeline them
|
|
||||||
this.offlineQueue = new Queue() // Holds commands issued but not able to be sent
|
|
||||||
this._pipelineQueue = new Queue() // Holds all pipelined commands
|
this._pipelineQueue = new Queue() // Holds all pipelined commands
|
||||||
// Only used as timeout until redis has to be connected to redis until throwing an connection error
|
this._pubSubMode = 0
|
||||||
this.connectTimeout = +options.connectTimeout || 60000 // 60 * 1000 ms
|
this._subscriptionSet = {}
|
||||||
this.enableOfflineQueue = options.enableOfflineQueue !== false
|
this._monitoring = false
|
||||||
this.pubSubMode = 0
|
|
||||||
this.subscriptionSet = {}
|
|
||||||
this.monitoring = false
|
|
||||||
this.messageBuffers = false
|
this.messageBuffers = false
|
||||||
this.closing = false
|
this._closing = false
|
||||||
this.serverInfo = {}
|
if (options.authPass) {
|
||||||
this.authPass = options.authPass || options.password
|
if (options.password) {
|
||||||
|
throw new TypeError('The "password" and "authPass" option may not both be set at the same time.')
|
||||||
|
}
|
||||||
|
options.password = options.authPass
|
||||||
|
}
|
||||||
this.selectedDb = options.db // Save the selected db here, used when reconnecting
|
this.selectedDb = options.db // Save the selected db here, used when reconnecting
|
||||||
this.oldState = null
|
|
||||||
this._strCache = ''
|
this._strCache = ''
|
||||||
this._pipeline = false
|
this._pipeline = false
|
||||||
this.subCommandsLeft = 0
|
this._subCommandsLeft = 0
|
||||||
this.renameCommands = options.renameCommands || {}
|
|
||||||
this.timesConnected = 0
|
this.timesConnected = 0
|
||||||
this.buffers = options.returnBuffers || options.detectBuffers
|
this.buffers = options.returnBuffers || options.detectBuffers
|
||||||
this.options = options
|
this._options = options
|
||||||
this._multi = false
|
this._multi = false
|
||||||
this.reply = 'ON' // Returning replies is the default
|
this._reply = 'ON' // Returning replies is the default
|
||||||
this.retryStrategy = options.retryStrategy || function (options) {
|
this.retryStrategy = options.retryStrategy || function (options) {
|
||||||
if (options.attempt > 100) {
|
if (options.attempt > 100) {
|
||||||
return
|
return
|
||||||
@@ -113,8 +124,8 @@ class RedisClient extends EventEmitter {
|
|||||||
// reconnect after
|
// reconnect after
|
||||||
return Math.min(options.attempt * 100, 3000)
|
return Math.min(options.attempt * 100, 3000)
|
||||||
}
|
}
|
||||||
this.retryStrategyProvided = !!options.retryStrategy
|
this._retryStrategyProvided = !!options.retryStrategy
|
||||||
this.subscribeChannels = []
|
this._subscribeChannels = []
|
||||||
utils.setReconnectDefaults(this)
|
utils.setReconnectDefaults(this)
|
||||||
// Init parser and connect
|
// Init parser and connect
|
||||||
connect(this)
|
connect(this)
|
||||||
@@ -128,6 +139,7 @@ class RedisClient extends EventEmitter {
|
|||||||
|
|
||||||
// Do not call internalSendCommand directly, if you are not absolutely certain it handles everything properly
|
// 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
|
// e.g. monitor / info does not work with internalSendCommand only
|
||||||
|
// TODO: Move this function out of the client as a private function
|
||||||
internalSendCommand (commandObj) {
|
internalSendCommand (commandObj) {
|
||||||
if (this.ready === false || this._stream.writable === false) {
|
if (this.ready === false || this._stream.writable === false) {
|
||||||
// Handle offline commands right away
|
// Handle offline commands right away
|
||||||
@@ -143,16 +155,16 @@ class RedisClient extends EventEmitter {
|
|||||||
// Handle `CLIENT REPLY ON|OFF|SKIP`
|
// Handle `CLIENT REPLY ON|OFF|SKIP`
|
||||||
// This has to be checked after callOnWrite
|
// This has to be checked after callOnWrite
|
||||||
/* istanbul ignore else: TODO: Remove this as soon as we test Redis 3.2 on travis */
|
/* istanbul ignore else: TODO: Remove this as soon as we test Redis 3.2 on travis */
|
||||||
if (this.reply === 'ON') {
|
if (this._reply === 'ON') {
|
||||||
this.commandQueue.push(commandObj)
|
this.commandQueue.push(commandObj)
|
||||||
} else {
|
} else {
|
||||||
// Do not expect a reply
|
// Do not expect a reply
|
||||||
// Does this work in combination with the pub sub mode?
|
// Does this work in combination with the pub sub mode?
|
||||||
utils.replyInOrder(this, commandObj.callback, null, undefined, this.commandQueue)
|
utils.replyInOrder(this, commandObj.callback, null, undefined, this.commandQueue)
|
||||||
if (this.reply === 'SKIP') {
|
if (this._reply === 'SKIP') {
|
||||||
this.reply = 'SKIP_ONE_MORE'
|
this._reply = 'SKIP_ONE_MORE'
|
||||||
} else if (this.reply === 'SKIP_ONE_MORE') {
|
} else if (this._reply === 'SKIP_ONE_MORE') {
|
||||||
this.reply = 'ON'
|
this._reply = 'ON'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commandObj.promise
|
return commandObj.promise
|
||||||
@@ -202,7 +214,7 @@ class RedisClient extends EventEmitter {
|
|||||||
this._stream.on('error', noop)
|
this._stream.on('error', noop)
|
||||||
this.connected = false
|
this.connected = false
|
||||||
this.ready = false
|
this.ready = false
|
||||||
this.closing = true
|
this._closing = true
|
||||||
return this._stream.destroySoon()
|
return this._stream.destroySoon()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,9 +224,7 @@ class RedisClient extends EventEmitter {
|
|||||||
this._stream.unref()
|
this._stream.unref()
|
||||||
} else {
|
} else {
|
||||||
debug('Not connected yet, will unref later')
|
debug('Not connected yet, will unref later')
|
||||||
this.once('connect', function () {
|
this.once('connect', () => this._stream.unref())
|
||||||
this.unref()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +234,7 @@ class RedisClient extends EventEmitter {
|
|||||||
callback = options
|
callback = options
|
||||||
options = null
|
options = null
|
||||||
}
|
}
|
||||||
const existingOptions = utils.clone(this.options)
|
const existingOptions = utils.clone(this._options)
|
||||||
options = utils.clone(options)
|
options = utils.clone(options)
|
||||||
for (const elem in options) {
|
for (const elem in options) {
|
||||||
if (options.hasOwnProperty(elem)) {
|
if (options.hasOwnProperty(elem)) {
|
||||||
@@ -234,11 +244,11 @@ class RedisClient extends EventEmitter {
|
|||||||
const client = new RedisClient(existingOptions)
|
const client = new RedisClient(existingOptions)
|
||||||
client.selectedDb = this.selectedDb
|
client.selectedDb = this.selectedDb
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
const errorListener = function (err) {
|
const errorListener = (err) => {
|
||||||
callback(err)
|
callback(err)
|
||||||
client.end(true)
|
client.end(true)
|
||||||
}
|
}
|
||||||
const readyListener = function () {
|
const readyListener = () => {
|
||||||
callback(null, client)
|
callback(null, client)
|
||||||
client.removeAllListeners(errorListener)
|
client.removeAllListeners(errorListener)
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ var reconnect = function (client, why, err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onStreamError (client, err) {
|
function onStreamError (client, err) {
|
||||||
if (client.closing) {
|
if (client._closing) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ function onStreamError (client, err) {
|
|||||||
client.ready = false
|
client.ready = false
|
||||||
|
|
||||||
// Only emit the error if the retryStrategy option is not set
|
// Only emit the error if the retryStrategy option is not set
|
||||||
if (client.retryStrategyProvided === false) {
|
if (client._retryStrategyProvided === false) {
|
||||||
client.emit('error', err)
|
client.emit('error', err)
|
||||||
}
|
}
|
||||||
// 'error' events get turned into exceptions if they aren't listened for. If the user handled this error
|
// 'error' events get turned into exceptions if they aren't listened for. If the user handled this error
|
||||||
@@ -61,7 +61,7 @@ function createParser (client) {
|
|||||||
setImmediate(() => client.emit('error', err))
|
setImmediate(() => client.emit('error', err))
|
||||||
},
|
},
|
||||||
returnBuffers: client.buffers || client.messageBuffers,
|
returnBuffers: client.buffers || client.messageBuffers,
|
||||||
stringNumbers: client.options.stringNumbers || false
|
stringNumbers: client._options.stringNumbers || false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ function connect (client) {
|
|||||||
const parser = createParser(client)
|
const parser = createParser(client)
|
||||||
client._replyParser = parser
|
client._replyParser = parser
|
||||||
|
|
||||||
if (client.options.stream) {
|
if (client._options.stream) {
|
||||||
// Only add the listeners once in case of a reconnect try (that won't work)
|
// Only add the listeners once in case of a reconnect try (that won't work)
|
||||||
if (client._stream) {
|
if (client._stream) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client._stream = client.options.stream
|
client._stream = client._options.stream
|
||||||
} else {
|
} else {
|
||||||
// On a reconnect destroy the former stream and retry
|
// On a reconnect destroy the former stream and retry
|
||||||
if (client._stream) {
|
if (client._stream) {
|
||||||
@@ -92,25 +92,25 @@ function connect (client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore if: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */
|
/* istanbul ignore if: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */
|
||||||
if (client.options.tls) {
|
if (client._options.tls) {
|
||||||
client._stream = tls.connect(client.connectionOptions)
|
client._stream = tls.connect(client._connectionOptions)
|
||||||
} else {
|
} else {
|
||||||
client._stream = net.createConnection(client.connectionOptions)
|
client._stream = net.createConnection(client._connectionOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = client._stream
|
const stream = client._stream
|
||||||
|
|
||||||
if (client.options.connectTimeout) {
|
if (client._options.connectTimeout) {
|
||||||
// TODO: Investigate why this is not properly triggered
|
// TODO: Investigate why this is not properly triggered
|
||||||
stream.setTimeout(client.connectTimeout, () => {
|
stream.setTimeout(client._options.connectTimeout, () => {
|
||||||
// Note: This is only tested if a internet connection is established
|
// Note: This is only tested if a internet connection is established
|
||||||
reconnect(client, 'timeout')
|
reconnect(client, 'timeout')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */
|
/* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */
|
||||||
const connectEvent = client.options.tls ? 'secureConnect' : 'connect'
|
const connectEvent = client._options.tls ? 'secureConnect' : 'connect'
|
||||||
stream.once(connectEvent, () => {
|
stream.once(connectEvent, () => {
|
||||||
stream.removeAllListeners('timeout')
|
stream.removeAllListeners('timeout')
|
||||||
client.timesConnected++
|
client.timesConnected++
|
||||||
@@ -142,11 +142,13 @@ function connect (client) {
|
|||||||
|
|
||||||
stream.setNoDelay()
|
stream.setNoDelay()
|
||||||
|
|
||||||
// Fire the command before redis is connected to be sure it's the first fired command
|
// Fire the command before redis is connected to be sure it's the first fired command.
|
||||||
if (client.authPass !== undefined) {
|
// TODO: Consider calling the ready check before Redis is connected as well.
|
||||||
|
// That could improve the ready performance. Measure the rough time difference!
|
||||||
|
if (client._options.password !== undefined) {
|
||||||
client.ready = true
|
client.ready = true
|
||||||
client.auth(client.authPass).catch((err) => {
|
client.auth(client._options.password).catch((err) => {
|
||||||
client.closing = true
|
client._closing = true
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
client.emit('error', err)
|
client.emit('error', err)
|
||||||
client.end(true)
|
client.end(true)
|
||||||
|
@@ -46,7 +46,7 @@ RedisClient.prototype.monitor = function monitor () {
|
|||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// Activating monitor mode has to happen before Redis returned the callback. The monitor result is returned first.
|
// 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.
|
// Therefore we expect the command to be properly processed. If this is not the case, it's not an issue either.
|
||||||
this.monitoring = true
|
this._monitoring = true
|
||||||
}
|
}
|
||||||
return this.internalSendCommand(new Command('monitor', [], callOnWrite))
|
return this.internalSendCommand(new Command('monitor', [], callOnWrite))
|
||||||
}
|
}
|
||||||
@@ -54,16 +54,16 @@ RedisClient.prototype.monitor = function monitor () {
|
|||||||
// Only works with batch, not in a transaction
|
// Only works with batch, not in a transaction
|
||||||
Multi.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
|
// 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) {
|
if (this._type !== 'multi') {
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
this._client.monitoring = true
|
this._client._monitoring = true
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('monitor', [], callOnWrite))
|
this._queue.push(new Command('monitor', [], callOnWrite))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
// Set multi monitoring to indicate the exec that it should abort
|
// Set multi monitoring to indicate the exec that it should abort
|
||||||
// Remove this "hack" as soon as Redis might fix this
|
// Remove this "hack" as soon as Redis might fix this
|
||||||
this.monitoring = true
|
this._monitoring = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ RedisClient.prototype.quit = function quit () {
|
|||||||
// this.ready = this.offlineQueue.length === 0;
|
// this.ready = this.offlineQueue.length === 0;
|
||||||
const backpressureIndicator = this.internalSendCommand(new Command('quit', [], null, quitCallback(this)))
|
const backpressureIndicator = this.internalSendCommand(new Command('quit', [], null, quitCallback(this)))
|
||||||
// Calling quit should always end the connection, no matter if there's a connection or not
|
// Calling quit should always end the connection, no matter if there's a connection or not
|
||||||
this.closing = true
|
this._closing = true
|
||||||
this.ready = false
|
this.ready = false
|
||||||
return backpressureIndicator
|
return backpressureIndicator
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ RedisClient.prototype.quit = function quit () {
|
|||||||
Multi.prototype.quit = function quit () {
|
Multi.prototype.quit = function quit () {
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// If called in a multi context, we expect redis is available
|
// If called in a multi context, we expect redis is available
|
||||||
this._client.closing = true
|
this._client._closing = true
|
||||||
this._client.ready = false
|
this._client.ready = false
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite))
|
this._queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite))
|
||||||
@@ -198,7 +198,7 @@ RedisClient.prototype.auth = function auth (pass) {
|
|||||||
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
||||||
|
|
||||||
// Stash auth for connect and reconnect.
|
// Stash auth for connect and reconnect.
|
||||||
this.authPass = pass
|
this._options.password = pass
|
||||||
const ready = this.ready
|
const ready = this.ready
|
||||||
this.ready = ready || this.offlineQueue.length === 0
|
this.ready = ready || this.offlineQueue.length === 0
|
||||||
const tmp = this.internalSendCommand(new Command('auth', [pass], null, authCallback(this, pass)))
|
const tmp = this.internalSendCommand(new Command('auth', [pass], null, authCallback(this, pass)))
|
||||||
@@ -211,7 +211,7 @@ Multi.prototype.auth = function auth (pass) {
|
|||||||
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
||||||
|
|
||||||
// Stash auth for connect and reconnect.
|
// Stash auth for connect and reconnect.
|
||||||
this.authPass = pass
|
this._client._options.password = pass
|
||||||
this._queue.push(new Command('auth', [pass], null, authCallback(this._client)))
|
this._queue.push(new Command('auth', [pass], null, authCallback(this._client)))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ RedisClient.prototype.client = function client () {
|
|||||||
const replyOnOff = arr[1].toString().toUpperCase()
|
const replyOnOff = arr[1].toString().toUpperCase()
|
||||||
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
||||||
callOnWrite = () => {
|
callOnWrite = () => {
|
||||||
this.reply = replyOnOff
|
this._reply = replyOnOff
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ Multi.prototype.client = function client () {
|
|||||||
const replyOnOff = arr[1].toString().toUpperCase()
|
const replyOnOff = arr[1].toString().toUpperCase()
|
||||||
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
||||||
callOnWrite = () => {
|
callOnWrite = () => {
|
||||||
this._client.reply = replyOnOff
|
this._client._reply = replyOnOff
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ RedisClient.prototype.subscribe = function subscribe () {
|
|||||||
arr[i] = arguments[i]
|
arr[i] = arguments[i]
|
||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
|
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
return this.internalSendCommand(new Command('subscribe', arr, callOnWrite))
|
return this.internalSendCommand(new Command('subscribe', arr, callOnWrite))
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ Multi.prototype.subscribe = function subscribe () {
|
|||||||
arr[i] = arguments[i]
|
arr[i] = arguments[i]
|
||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('subscribe', arr, callOnWrite))
|
this._queue.push(new Command('subscribe', arr, callOnWrite))
|
||||||
return this
|
return this
|
||||||
@@ -290,7 +290,7 @@ RedisClient.prototype.unsubscribe = function unsubscribe () {
|
|||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||||
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
|
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
return this.internalSendCommand(new Command('unsubscribe', arr, callOnWrite))
|
return this.internalSendCommand(new Command('unsubscribe', arr, callOnWrite))
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ Multi.prototype.unsubscribe = function unsubscribe () {
|
|||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('unsubscribe', arr, callOnWrite))
|
this._queue.push(new Command('unsubscribe', arr, callOnWrite))
|
||||||
return this
|
return this
|
||||||
@@ -316,7 +316,7 @@ RedisClient.prototype.psubscribe = function psubscribe () {
|
|||||||
arr[i] = arguments[i]
|
arr[i] = arguments[i]
|
||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
|
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
return this.internalSendCommand(new Command('psubscribe', arr, callOnWrite))
|
return this.internalSendCommand(new Command('psubscribe', arr, callOnWrite))
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ Multi.prototype.psubscribe = function psubscribe () {
|
|||||||
arr[i] = arguments[i]
|
arr[i] = arguments[i]
|
||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('psubscribe', arr, callOnWrite))
|
this._queue.push(new Command('psubscribe', arr, callOnWrite))
|
||||||
return this
|
return this
|
||||||
@@ -342,7 +342,7 @@ RedisClient.prototype.punsubscribe = function punsubscribe () {
|
|||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||||
this.pubSubMode = this.pubSubMode || this.commandQueue.length + 1
|
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
return this.internalSendCommand(new Command('punsubscribe', arr, callOnWrite))
|
return this.internalSendCommand(new Command('punsubscribe', arr, callOnWrite))
|
||||||
}
|
}
|
||||||
@@ -355,7 +355,7 @@ Multi.prototype.punsubscribe = function punsubscribe () {
|
|||||||
}
|
}
|
||||||
const callOnWrite = () => {
|
const callOnWrite = () => {
|
||||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||||
}
|
}
|
||||||
this._queue.push(new Command('punsubscribe', arr, callOnWrite))
|
this._queue.push(new Command('punsubscribe', arr, callOnWrite))
|
||||||
return this
|
return this
|
||||||
|
@@ -22,7 +22,7 @@ function pipelineTransactionCommand (multi, command, index) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
tmp(err)
|
tmp(err)
|
||||||
err.position = index
|
err.position = index
|
||||||
multi.errors.push(err)
|
multi._errors.push(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmp(null, reply)
|
tmp(null, reply)
|
||||||
@@ -73,7 +73,7 @@ function multiCallback (multi, replies) {
|
|||||||
function execTransaction (multi) {
|
function execTransaction (multi) {
|
||||||
const client = multi._client
|
const client = multi._client
|
||||||
const queue = multi._queue
|
const queue = multi._queue
|
||||||
if (multi.monitoring || client.monitoring) {
|
if (multi._monitoring || client._monitoring) {
|
||||||
const 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.'
|
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
|
||||||
)
|
)
|
||||||
@@ -87,9 +87,8 @@ function execTransaction (multi) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const len = queue.length
|
const len = queue.length
|
||||||
multi.errors = []
|
multi._errors = []
|
||||||
client._multi = true
|
client._multi = true
|
||||||
multi.wantsBuffers = new Array(len)
|
|
||||||
// Silently ignore this error. We'll receive the error for the exec as well
|
// Silently ignore this error. We'll receive the error for the exec as well
|
||||||
const promises = [client.internalSendCommand(new Command('multi', [])).catch(() => {})]
|
const promises = [client.internalSendCommand(new Command('multi', [])).catch(() => {})]
|
||||||
// Drain queue, callback will catch 'QUEUED' or error
|
// Drain queue, callback will catch 'QUEUED' or error
|
||||||
@@ -100,7 +99,7 @@ function execTransaction (multi) {
|
|||||||
|
|
||||||
const main = client.internalSendCommand(new Command('exec', []))
|
const main = client.internalSendCommand(new Command('exec', []))
|
||||||
return Promise.all(promises).then(() => main.then((replies) => multiCallback(multi, replies)).catch((err) => {
|
return Promise.all(promises).then(() => main.then((replies) => multiCallback(multi, replies)).catch((err) => {
|
||||||
err.errors = multi.errors
|
err.errors = multi._errors
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,8 @@ const utils = require('./utils')
|
|||||||
|
|
||||||
function offlineCommand (client, command) {
|
function offlineCommand (client, command) {
|
||||||
const commandName = command.command.toUpperCase()
|
const commandName = command.command.toUpperCase()
|
||||||
if (client.closing || !client.enableOfflineQueue) {
|
if (client._closing || client._options.enableOfflineQueue === false) {
|
||||||
const msg = client.closing === true
|
const msg = client._closing === true
|
||||||
? 'The connection is already closed.'
|
? 'The connection is already closed.'
|
||||||
: client._stream.writable === true
|
: client._stream.writable === true
|
||||||
? 'The connection is not yet established and the offline queue is deactivated.'
|
? 'The connection is not yet established and the offline queue is deactivated.'
|
||||||
|
@@ -12,7 +12,7 @@ function subscribeUnsubscribe (client, reply, type) {
|
|||||||
// Subscribe commands take an optional callback and also emit an event, but only the Last_ response is included in the callback
|
// Subscribe commands take an optional callback and also emit an event, but only the Last_ response is included in the callback
|
||||||
// The pub sub commands return each argument in a separate return value and have to be handled that way
|
// The pub sub commands return each argument in a separate return value and have to be handled that way
|
||||||
const commandObj = client.commandQueue.get(0)
|
const commandObj = client.commandQueue.get(0)
|
||||||
const buffer = client.options.returnBuffers || client.options.detectBuffers && commandObj.bufferArgs
|
const buffer = client._options.returnBuffers || client._options.detectBuffers && commandObj.bufferArgs
|
||||||
const channel = (buffer || reply[1] === null) ? reply[1] : reply[1].toString()
|
const channel = (buffer || reply[1] === null) ? reply[1] : reply[1].toString()
|
||||||
const count = +reply[2] // Return the channel counter as number no matter if `stringNumbers` is activated or not
|
const count = +reply[2] // Return the channel counter as number no matter if `stringNumbers` is activated or not
|
||||||
debug(type, channel)
|
debug(type, channel)
|
||||||
@@ -20,38 +20,38 @@ function subscribeUnsubscribe (client, reply, type) {
|
|||||||
// Emit first, then return the callback
|
// Emit first, then return the callback
|
||||||
if (channel !== null) { // Do not emit or "unsubscribe" something if there was no channel to unsubscribe from
|
if (channel !== null) { // Do not emit or "unsubscribe" something if there was no channel to unsubscribe from
|
||||||
if (type === 'subscribe' || type === 'psubscribe') {
|
if (type === 'subscribe' || type === 'psubscribe') {
|
||||||
client.subscriptionSet[`${type}_${channel}`] = channel
|
client._subscriptionSet[`${type}_${channel}`] = channel
|
||||||
} else {
|
} else {
|
||||||
const innerType = type === 'unsubscribe' ? 'subscribe' : 'psubscribe' // Make types consistent
|
const innerType = type === 'unsubscribe' ? 'subscribe' : 'psubscribe' // Make types consistent
|
||||||
delete client.subscriptionSet[`${innerType}_${channel}`]
|
delete client._subscriptionSet[`${innerType}_${channel}`]
|
||||||
}
|
}
|
||||||
client.emit(type, channel, count)
|
client.emit(type, channel, count)
|
||||||
client.subscribeChannels.push(channel)
|
client._subscribeChannels.push(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandObj.argsLength === 1 || client.subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) {
|
if (commandObj.argsLength === 1 || client._subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) {
|
||||||
if (count === 0) { // Unsubscribed from all channels
|
if (count === 0) { // Unsubscribed from all channels
|
||||||
var runningCommand
|
var runningCommand
|
||||||
var i = 1
|
var i = 1
|
||||||
client.pubSubMode = 0 // Deactivating pub sub mode
|
client._pubSubMode = 0 // Deactivating pub sub mode
|
||||||
// This should be a rare case and therefore handling it this way should be good performance wise for the general case
|
// This should be a rare case and therefore handling it this way should be good performance wise for the general case
|
||||||
for (runningCommand = client.commandQueue.get(i); runningCommand !== undefined; runningCommand = client.commandQueue.get(i)) {
|
for (runningCommand = client.commandQueue.get(i); runningCommand !== undefined; runningCommand = client.commandQueue.get(i)) {
|
||||||
if (SUBSCRIBE_COMMANDS[runningCommand.command]) {
|
if (SUBSCRIBE_COMMANDS[runningCommand.command]) {
|
||||||
client.pubSubMode = i // Entering pub sub mode again
|
client._pubSubMode = i // Entering pub sub mode again
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.commandQueue.shift()
|
client.commandQueue.shift()
|
||||||
commandObj.callback(null, [count, client.subscribeChannels])
|
commandObj.callback(null, [count, client._subscribeChannels])
|
||||||
client.subscribeChannels = []
|
client._subscribeChannels = []
|
||||||
client.subCommandsLeft = 0
|
client._subCommandsLeft = 0
|
||||||
} else {
|
} else {
|
||||||
if (client.subCommandsLeft !== 0) {
|
if (client._subCommandsLeft !== 0) {
|
||||||
client.subCommandsLeft--
|
client._subCommandsLeft--
|
||||||
} else {
|
} else {
|
||||||
client.subCommandsLeft = commandObj.argsLength ? commandObj.argsLength - 1 : count
|
client._subCommandsLeft = commandObj.argsLength ? commandObj.argsLength - 1 : count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,14 +59,14 @@ function subscribeUnsubscribe (client, reply, type) {
|
|||||||
function returnPubSub (client, reply) {
|
function returnPubSub (client, reply) {
|
||||||
const type = reply[0].toString()
|
const type = reply[0].toString()
|
||||||
if (type === 'message') { // Channel, message
|
if (type === 'message') { // Channel, message
|
||||||
if (!client.options.returnBuffers || client.messageBuffers) { // Backwards compatible. Refactor this in v.3 to always return a string on the normal emitter
|
if (!client._options.returnBuffers || client.messageBuffers) { // Backwards compatible. Refactor this in v.3 to always return a string on the normal emitter
|
||||||
client.emit('message', reply[1].toString(), reply[2].toString())
|
client.emit('message', reply[1].toString(), reply[2].toString())
|
||||||
client.emit('messageBuffer', reply[1], reply[2])
|
client.emit('messageBuffer', reply[1], reply[2])
|
||||||
} else {
|
} else {
|
||||||
client.emit('message', reply[1], reply[2])
|
client.emit('message', reply[1], reply[2])
|
||||||
}
|
}
|
||||||
} else if (type === 'pmessage') { // Pattern, channel, message
|
} else if (type === 'pmessage') { // Pattern, channel, message
|
||||||
if (!client.options.returnBuffers || client.messageBuffers) { // Backwards compatible. Refactor this in v.3 to always return a string on the normal emitter
|
if (!client._options.returnBuffers || client.messageBuffers) { // Backwards compatible. Refactor this in v.3 to always return a string on the normal emitter
|
||||||
client.emit('pmessage', reply[1].toString(), reply[2].toString(), reply[3].toString())
|
client.emit('pmessage', reply[1].toString(), reply[2].toString(), reply[3].toString())
|
||||||
client.emit('pmessageBuffer', reply[1], reply[2], reply[3])
|
client.emit('pmessageBuffer', reply[1], reply[2], reply[3])
|
||||||
} else {
|
} else {
|
||||||
|
@@ -11,14 +11,14 @@ function onConnect (client) {
|
|||||||
// fast properties. If that's not the case, make them fast properties
|
// fast properties. If that's not the case, make them fast properties
|
||||||
// again!
|
// again!
|
||||||
client.connected = true
|
client.connected = true
|
||||||
client._stream.setKeepAlive(client.options.socketKeepalive)
|
client._stream.setKeepAlive(client._options.socketKeepalive)
|
||||||
client._stream.setTimeout(0)
|
client._stream.setTimeout(0)
|
||||||
|
|
||||||
// TODO: Deprecate the connect event.
|
// TODO: Deprecate the connect event.
|
||||||
client.emit('connect')
|
client.emit('connect')
|
||||||
utils.setReconnectDefaults(client)
|
utils.setReconnectDefaults(client)
|
||||||
|
|
||||||
if (client.options.noReadyCheck) {
|
if (client._options.noReadyCheck) {
|
||||||
readyHandler(client)
|
readyHandler(client)
|
||||||
} else {
|
} else {
|
||||||
readyCheck(client)
|
readyCheck(client)
|
||||||
@@ -53,21 +53,21 @@ function readyHandler (client) {
|
|||||||
|
|
||||||
if (client.selectedDb !== undefined) {
|
if (client.selectedDb !== undefined) {
|
||||||
client.internalSendCommand(new Command('select', [client.selectedDb])).catch((err) => {
|
client.internalSendCommand(new Command('select', [client.selectedDb])).catch((err) => {
|
||||||
if (!client.closing) {
|
if (!client._closing) {
|
||||||
// TODO: These internal things should be wrapped in a
|
// TODO: These internal things should be wrapped in a
|
||||||
// special error that describes what is happening
|
// special error that describes what is happening
|
||||||
process.nextTick(client.emit, 'error', err)
|
process.nextTick(client.emit, 'error', err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (client.monitoring) { // Monitor has to be fired before pub sub commands
|
if (client._monitoring) { // Monitor has to be fired before pub sub commands
|
||||||
client.internalSendCommand(new Command('monitor', [])).catch((err) => {
|
client.internalSendCommand(new Command('monitor', [])).catch((err) => {
|
||||||
if (!client.closing) {
|
if (!client._closing) {
|
||||||
process.nextTick(client.emit, 'error', err)
|
process.nextTick(client.emit, 'error', err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const callbackCount = Object.keys(client.subscriptionSet).length
|
const callbackCount = Object.keys(client._subscriptionSet).length
|
||||||
// TODO: Replace the disableResubscribing by a individual function that may be called
|
// TODO: Replace the disableResubscribing by a individual function that may be called
|
||||||
// Add HOOKS!!!
|
// Add HOOKS!!!
|
||||||
// Replace the disableResubscribing by:
|
// Replace the disableResubscribing by:
|
||||||
@@ -77,14 +77,14 @@ function readyHandler (client) {
|
|||||||
// subscriptions: true,
|
// subscriptions: true,
|
||||||
// // individual: function noop () {}
|
// // individual: function noop () {}
|
||||||
// }
|
// }
|
||||||
if (!client.options.disableResubscribing && callbackCount) {
|
if (!client._options.disableResubscribing && callbackCount) {
|
||||||
debug('Sending pub/sub commands')
|
debug('Sending pub/sub commands')
|
||||||
for (const key in client.subscriptionSet) {
|
for (const key in client._subscriptionSet) {
|
||||||
if (client.subscriptionSet.hasOwnProperty(key)) {
|
if (client._subscriptionSet.hasOwnProperty(key)) {
|
||||||
const command = key.slice(0, key.indexOf('_'))
|
const command = key.slice(0, key.indexOf('_'))
|
||||||
const args = client.subscriptionSet[key]
|
const args = client._subscriptionSet[key]
|
||||||
client[command]([args]).catch((err) => {
|
client[command]([args]).catch((err) => {
|
||||||
if (!client.closing) {
|
if (!client._closing) {
|
||||||
process.nextTick(client.emit, 'error', err)
|
process.nextTick(client.emit, 'error', err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -133,7 +133,7 @@ function readyCheck (client) {
|
|||||||
debug('Redis server still loading, trying again in %s', retryTime)
|
debug('Redis server still loading, trying again in %s', retryTime)
|
||||||
setTimeout((client) => readyCheck(client), retryTime, client)
|
setTimeout((client) => readyCheck(client), retryTime, client)
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
if (client.closing) {
|
if (client._closing) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ function reconnect (client, why, error) {
|
|||||||
debug('Redis connection is gone from %s event.', why)
|
debug('Redis connection is gone from %s event.', why)
|
||||||
client.connected = false
|
client.connected = false
|
||||||
client.ready = false
|
client.ready = false
|
||||||
client.pubSubMode = 0
|
client._pubSubMode = 0
|
||||||
|
|
||||||
client.emit('end')
|
client.emit('end')
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ function reconnect (client, why, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If client is a requested shutdown, then don't retry
|
// If client is a requested shutdown, then don't retry
|
||||||
if (client.closing) {
|
if (client._closing) {
|
||||||
debug('Connection ended by quit / end command, not retrying.')
|
debug('Connection ended by quit / end command, not retrying.')
|
||||||
flushAndError(client, 'Stream connection ended and command aborted.', 'NR_CLOSED', {
|
flushAndError(client, 'Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||||
error
|
error
|
||||||
@@ -94,7 +94,7 @@ function reconnect (client, why, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retry commands after a reconnect instead of throwing an error. Use this with caution
|
// Retry commands after a reconnect instead of throwing an error. Use this with caution
|
||||||
if (client.options.retryUnfulfilledCommands) {
|
if (client._options.retryUnfulfilledCommands) {
|
||||||
client.offlineQueue.unshift.apply(client.offlineQueue, client.commandQueue.toArray())
|
client.offlineQueue.unshift.apply(client.offlineQueue, client.commandQueue.toArray())
|
||||||
client.commandQueue.clear()
|
client.commandQueue.clear()
|
||||||
// TODO: If only the pipelineQueue contains the error we could improve the situation.
|
// TODO: If only the pipelineQueue contains the error we could improve the situation.
|
||||||
|
@@ -15,8 +15,8 @@ function onError (client, err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count down pub sub mode if in entering modus
|
// Count down pub sub mode if in entering modus
|
||||||
if (client.pubSubMode > 1) {
|
if (client._pubSubMode > 1) {
|
||||||
client.pubSubMode--
|
client._pubSubMode--
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = err.message.match(utils.errCode)
|
const match = err.message.match(utils.errCode)
|
||||||
@@ -40,7 +40,7 @@ function onResult (client, reply) {
|
|||||||
// If in monitor mode, all normal commands are still working and we only want to emit the streamlined commands
|
// If in monitor mode, all normal commands are still working and we only want to emit the streamlined commands
|
||||||
// As this is not the average use case and monitor is expensive anyway, let's change the code here, to improve
|
// As this is not the average use case and monitor is expensive anyway, let's change the code here, to improve
|
||||||
// the average performance of all other commands in case of no monitor mode
|
// the average performance of all other commands in case of no monitor mode
|
||||||
if (client.monitoring) {
|
if (client._monitoring) {
|
||||||
var replyStr
|
var replyStr
|
||||||
if (client.buffers && Buffer.isBuffer(reply)) {
|
if (client.buffers && Buffer.isBuffer(reply)) {
|
||||||
replyStr = reply.toString()
|
replyStr = reply.toString()
|
||||||
@@ -58,10 +58,10 @@ function onResult (client, reply) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (client.pubSubMode === 0) {
|
if (client._pubSubMode === 0) {
|
||||||
normalReply(client, reply)
|
normalReply(client, reply)
|
||||||
} else if (client.pubSubMode !== 1) {
|
} else if (client._pubSubMode !== 1) {
|
||||||
client.pubSubMode--
|
client._pubSubMode--
|
||||||
normalReply(client, reply)
|
normalReply(client, reply)
|
||||||
} else if (!(reply instanceof Array) || reply.length <= 2) {
|
} else if (!(reply instanceof Array) || reply.length <= 2) {
|
||||||
// Only PING and QUIT are allowed in this context besides the pub sub commands
|
// Only PING and QUIT are allowed in this context besides the pub sub commands
|
||||||
|
@@ -139,7 +139,7 @@ function warn (client, msg) {
|
|||||||
* @returns {string|number|null|Buffer|any[]|object}
|
* @returns {string|number|null|Buffer|any[]|object}
|
||||||
*/
|
*/
|
||||||
function handleReply (client, reply, command) {
|
function handleReply (client, reply, command) {
|
||||||
if (client.options.detectBuffers === true && command.bufferArgs === false) { // client.messageBuffers
|
if (client._options.detectBuffers === true && command.bufferArgs === false) { // client.messageBuffers
|
||||||
reply = replyToStrings(reply)
|
reply = replyToStrings(reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -128,8 +128,8 @@ function returnErr (client, command) {
|
|||||||
function normalizeAndWrite (client, command) {
|
function normalizeAndWrite (client, command) {
|
||||||
const args = command.args
|
const args = command.args
|
||||||
const origName = command.command
|
const origName = command.command
|
||||||
const renameCommands = client.renameCommands
|
const renameCommands = client._options.renameCommands
|
||||||
const name = renameCommands[origName] !== undefined
|
const name = renameCommands !== undefined && renameCommands[origName] !== undefined
|
||||||
? renameCommands[origName]
|
? renameCommands[origName]
|
||||||
: origName
|
: origName
|
||||||
|
|
||||||
@@ -142,12 +142,12 @@ function normalizeAndWrite (client, command) {
|
|||||||
return returnErr(client, command)
|
return returnErr(client, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof client.options.prefix === 'string') {
|
if (typeof client._options.prefix === 'string') {
|
||||||
const prefixKeys = Commands.getKeyIndexes(origName, copy)
|
const prefixKeys = Commands.getKeyIndexes(origName, copy)
|
||||||
prefixKeys.forEach((i) => {
|
prefixKeys.forEach((i) => {
|
||||||
// Attention it would be to expensive to detect if the input is non utf8 Buffer
|
// Attention it would be to expensive to detect if the input is non utf8 Buffer
|
||||||
// In that case the prefix *might* destroys user information
|
// In that case the prefix *might* destroys user information
|
||||||
copy[i] = client.options.prefix + copy[i]
|
copy[i] = client._options.prefix + copy[i]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,9 +72,8 @@ if (process.platform !== 'win32') {
|
|||||||
if (helper.redisProcess().spawnFailed()) this.skip()
|
if (helper.redisProcess().spawnFailed()) this.skip()
|
||||||
|
|
||||||
client = redis.createClient(`redis://${config.HOST[ip]}:${config.PORT}?db=2&password=${auth}`)
|
client = redis.createClient(`redis://${config.HOST[ip]}:${config.PORT}?db=2&password=${auth}`)
|
||||||
assert.strictEqual(client.options.db, '2')
|
assert.strictEqual(client._options.db, '2')
|
||||||
assert.strictEqual(client.options.password, auth)
|
assert.strictEqual(client._options.password, auth)
|
||||||
assert.strictEqual(client.authPass, auth)
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
const promises = []
|
const promises = []
|
||||||
// Set a key so the used database is returned in the info command
|
// Set a key so the used database is returned in the info command
|
||||||
@@ -209,7 +208,7 @@ if (process.platform !== 'win32') {
|
|||||||
client = redis.createClient.apply(null, args)
|
client = redis.createClient.apply(null, args)
|
||||||
client.set('foo', 'bar')
|
client.set('foo', 'bar')
|
||||||
client.subscribe('somechannel', 'another channel').then(() => {
|
client.subscribe('somechannel', 'another channel').then(() => {
|
||||||
assert.strictEqual(client.pubSubMode, 1)
|
assert.strictEqual(client._pubSubMode, 1)
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
client.get('foo').catch((err) => {
|
client.get('foo').catch((err) => {
|
||||||
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message))
|
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message))
|
||||||
@@ -219,7 +218,7 @@ if (process.platform !== 'win32') {
|
|||||||
})
|
})
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
// Coherent behavior with all other offline commands fires commands before emitting but does not wait till they return
|
// Coherent behavior with all other offline commands fires commands before emitting but does not wait till they return
|
||||||
assert.strictEqual(client.pubSubMode, 2)
|
assert.strictEqual(client._pubSubMode, 2)
|
||||||
client.ping().then(() => { // Make sure all commands were properly processed already
|
client.ping().then(() => { // Make sure all commands were properly processed already
|
||||||
client._stream.destroy()
|
client._stream.destroy()
|
||||||
})
|
})
|
||||||
|
@@ -46,27 +46,27 @@ describe('The \'client\' method', () => {
|
|||||||
describe('as normal command', () => {
|
describe('as normal command', () => {
|
||||||
it('on', function () {
|
it('on', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
const promises = [client.client('reply', 'on').then(helper.isString('OK'))]
|
const promises = [client.client('reply', 'on').then(helper.isString('OK'))]
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
promises.push(client.set('foo', 'bar'))
|
promises.push(client.set('foo', 'bar'))
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('off', function () {
|
it('off', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
const promises = [client.client(Buffer.from('REPLY'), 'OFF').then(helper.isUndefined())]
|
const promises = [client.client(Buffer.from('REPLY'), 'OFF').then(helper.isUndefined())]
|
||||||
assert.strictEqual(client.reply, 'OFF')
|
assert.strictEqual(client._reply, 'OFF')
|
||||||
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('skip', function () {
|
it('skip', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
const promises = [client.client('REPLY', Buffer.from('SKIP')).then(helper.isUndefined())]
|
const promises = [client.client('REPLY', Buffer.from('SKIP')).then(helper.isUndefined())]
|
||||||
assert.strictEqual(client.reply, 'SKIP_ONE_MORE')
|
assert.strictEqual(client._reply, 'SKIP_ONE_MORE')
|
||||||
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
||||||
promises.push(client.get('foo').then(helper.isString('bar')))
|
promises.push(client.get('foo').then(helper.isString('bar')))
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
@@ -77,9 +77,9 @@ describe('The \'client\' method', () => {
|
|||||||
it('on', function () {
|
it('on', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
const batch = client.batch()
|
const batch = client.batch()
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
batch.client('reply', 'on')
|
batch.client('reply', 'on')
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
batch.set('foo', 'bar')
|
batch.set('foo', 'bar')
|
||||||
return batch.exec().then(helper.isDeepEqual(['OK', 'OK']))
|
return batch.exec().then(helper.isDeepEqual(['OK', 'OK']))
|
||||||
})
|
})
|
||||||
@@ -87,20 +87,20 @@ describe('The \'client\' method', () => {
|
|||||||
it('off', function () {
|
it('off', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
const batch = client.batch()
|
const batch = client.batch()
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
batch.set('hello', 'world')
|
batch.set('hello', 'world')
|
||||||
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'))
|
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'))
|
||||||
batch.get('hello')
|
batch.get('hello')
|
||||||
batch.get('hello')
|
batch.get('hello')
|
||||||
return batch.exec().then((res) => {
|
return batch.exec().then((res) => {
|
||||||
assert.strictEqual(client.reply, 'OFF')
|
assert.strictEqual(client._reply, 'OFF')
|
||||||
assert.deepStrictEqual(res, ['OK', undefined, undefined, undefined])
|
assert.deepStrictEqual(res, ['OK', undefined, undefined, undefined])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('skip', function () {
|
it('skip', function () {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
return client.batch()
|
return client.batch()
|
||||||
.set('hello', 'world')
|
.set('hello', 'world')
|
||||||
.client('REPLY', 'SKIP')
|
.client('REPLY', 'SKIP')
|
||||||
@@ -108,7 +108,7 @@ describe('The \'client\' method', () => {
|
|||||||
.get('foo')
|
.get('foo')
|
||||||
.exec()
|
.exec()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
assert.strictEqual(client.reply, 'ON')
|
assert.strictEqual(client._reply, 'ON')
|
||||||
assert.deepStrictEqual(res, ['OK', undefined, undefined, 'bar'])
|
assert.deepStrictEqual(res, ['OK', undefined, undefined, 'bar'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -62,7 +62,7 @@ describe('The \'monitor\' method', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
monitorClient.on('monitor', (time, args, rawOutput) => {
|
monitorClient.on('monitor', (time, args, rawOutput) => {
|
||||||
assert.strictEqual(monitorClient.monitoring, true)
|
assert.strictEqual(monitorClient._monitoring, true)
|
||||||
assert.deepStrictEqual(args, responses.shift())
|
assert.deepStrictEqual(args, responses.shift())
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||||
if (responses.length === 0) {
|
if (responses.length === 0) {
|
||||||
@@ -81,7 +81,7 @@ describe('The \'monitor\' method', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
monitorClient.monitor().then((res) => {
|
monitorClient.monitor().then((res) => {
|
||||||
assert.strictEqual(monitorClient.monitoring, true)
|
assert.strictEqual(monitorClient._monitoring, true)
|
||||||
assert.strictEqual(res.inspect(), Buffer.from('OK').inspect())
|
assert.strictEqual(res.inspect(), Buffer.from('OK').inspect())
|
||||||
monitorClient.mget('hello', Buffer.from('world'))
|
monitorClient.mget('hello', Buffer.from('world'))
|
||||||
})
|
})
|
||||||
@@ -100,7 +100,7 @@ describe('The \'monitor\' method', () => {
|
|||||||
client.monitor().then(helper.isString('OK'))
|
client.monitor().then(helper.isString('OK'))
|
||||||
client.mget('hello', 'world')
|
client.mget('hello', 'world')
|
||||||
client.on('monitor', (time, args, rawOutput) => {
|
client.on('monitor', (time, args, rawOutput) => {
|
||||||
assert.strictEqual(client.monitoring, true)
|
assert.strictEqual(client._monitoring, true)
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||||
assert.deepStrictEqual(args, ['mget', 'hello', 'world'])
|
assert.deepStrictEqual(args, ['mget', 'hello', 'world'])
|
||||||
if (called) {
|
if (called) {
|
||||||
@@ -120,7 +120,7 @@ describe('The \'monitor\' method', () => {
|
|||||||
multi.mget('hello', 'world')
|
multi.mget('hello', 'world')
|
||||||
multi.exec().then(helper.isDeepEqual(['OK', [null, null]]))
|
multi.exec().then(helper.isDeepEqual(['OK', [null, null]]))
|
||||||
client.on('monitor', (time, args, rawOutput) => {
|
client.on('monitor', (time, args, rawOutput) => {
|
||||||
assert.strictEqual(client.monitoring, true)
|
assert.strictEqual(client._monitoring, true)
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||||
assert.deepStrictEqual(args, ['mget', 'hello', 'world'])
|
assert.deepStrictEqual(args, ['mget', 'hello', 'world'])
|
||||||
if (called) {
|
if (called) {
|
||||||
@@ -141,12 +141,12 @@ describe('The \'monitor\' method', () => {
|
|||||||
client._stream.destroy()
|
client._stream.destroy()
|
||||||
const end = helper.callFuncAfter(done, 2)
|
const end = helper.callFuncAfter(done, 2)
|
||||||
client.on('monitor', (time, args, rawOutput) => {
|
client.on('monitor', (time, args, rawOutput) => {
|
||||||
assert.strictEqual(client.monitoring, true)
|
assert.strictEqual(client._monitoring, true)
|
||||||
end()
|
end()
|
||||||
})
|
})
|
||||||
client.on('reconnecting', () => {
|
client.on('reconnecting', () => {
|
||||||
client.get('foo').then((res) => {
|
client.get('foo').then((res) => {
|
||||||
assert.strictEqual(client.monitoring, true)
|
assert.strictEqual(client._monitoring, true)
|
||||||
end()
|
end()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -23,8 +23,9 @@ describe('connection tests', () => {
|
|||||||
// Therefore this is not officially supported!
|
// Therefore this is not officially supported!
|
||||||
const socket = new net.Socket()
|
const socket = new net.Socket()
|
||||||
client = new redis.RedisClient({
|
client = new redis.RedisClient({
|
||||||
prefix: 'test'
|
prefix: 'test',
|
||||||
}, socket)
|
stream: socket
|
||||||
|
})
|
||||||
assert.strictEqual(client._stream, socket)
|
assert.strictEqual(client._stream, socket)
|
||||||
assert.strictEqual(client._stream.listeners('error').length, 1)
|
assert.strictEqual(client._stream.listeners('error').length, 1)
|
||||||
assert.strictEqual(client.address, '"Private stream"')
|
assert.strictEqual(client.address, '"Private stream"')
|
||||||
@@ -160,7 +161,7 @@ describe('connection tests', () => {
|
|||||||
retryStrategy () {}
|
retryStrategy () {}
|
||||||
}
|
}
|
||||||
client = redis.createClient(options)
|
client = redis.createClient(options)
|
||||||
assert.strictEqual(client.connectionOptions.family, ip === 'IPv6' ? 6 : 4)
|
assert.strictEqual(client._connectionOptions.family, ip === 'IPv6' ? 6 : 4)
|
||||||
assert.strictEqual(Object.keys(options).length, 4)
|
assert.strictEqual(Object.keys(options).length, 4)
|
||||||
const end = helper.callFuncAfter(done, 2)
|
const end = helper.callFuncAfter(done, 2)
|
||||||
|
|
||||||
@@ -246,7 +247,7 @@ describe('connection tests', () => {
|
|||||||
})
|
})
|
||||||
process.nextTick(() => assert.strictEqual(client._stream.listeners('timeout').length, 1))
|
process.nextTick(() => assert.strictEqual(client._stream.listeners('timeout').length, 1))
|
||||||
assert.strictEqual(client.address, '10.255.255.1:6379')
|
assert.strictEqual(client.address, '10.255.255.1:6379')
|
||||||
assert.strictEqual(client.connectionOptions.family, 4)
|
assert.strictEqual(client._connectionOptions.family, 4)
|
||||||
|
|
||||||
client.on('reconnecting', () => {
|
client.on('reconnecting', () => {
|
||||||
throw new Error('No reconnect, since no connection was ever established')
|
throw new Error('No reconnect, since no connection was ever established')
|
||||||
@@ -274,7 +275,7 @@ describe('connection tests', () => {
|
|||||||
host: '2001:db8::ff00:42:8329' // auto detect ip v6
|
host: '2001:db8::ff00:42:8329' // auto detect ip v6
|
||||||
})
|
})
|
||||||
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379')
|
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379')
|
||||||
assert.strictEqual(client.connectionOptions.family, 6)
|
assert.strictEqual(client._connectionOptions.family, 6)
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
assert.strictEqual(client._stream.listeners('timeout').length, 0)
|
assert.strictEqual(client._stream.listeners('timeout').length, 0)
|
||||||
done()
|
done()
|
||||||
@@ -337,7 +338,7 @@ describe('connection tests', () => {
|
|||||||
|
|
||||||
it('connects with a port only', (done) => {
|
it('connects with a port only', (done) => {
|
||||||
client = redis.createClient(6379)
|
client = redis.createClient(6379)
|
||||||
assert.strictEqual(client.connectionOptions.family, 4)
|
assert.strictEqual(client._connectionOptions.family, 4)
|
||||||
client.on('error', done)
|
client.on('error', done)
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
@@ -433,7 +434,7 @@ describe('connection tests', () => {
|
|||||||
client = redis.createClient('//127.0.0.1', {
|
client = redis.createClient('//127.0.0.1', {
|
||||||
connectTimeout: 1000
|
connectTimeout: 1000
|
||||||
})
|
})
|
||||||
assert.strictEqual(client.options.connectTimeout, 1000)
|
assert.strictEqual(client._options.connectTimeout, 1000)
|
||||||
client.on('ready', done)
|
client.on('ready', done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -441,10 +442,10 @@ describe('connection tests', () => {
|
|||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
url: `http://foo:porkchopsandwiches@${config.HOST[ip]}/3`
|
url: `http://foo:porkchopsandwiches@${config.HOST[ip]}/3`
|
||||||
})
|
})
|
||||||
assert.strictEqual(client.authPass, 'porkchopsandwiches')
|
assert.strictEqual(client._options.password, 'porkchopsandwiches')
|
||||||
assert.strictEqual(+client.selectedDb, 3)
|
assert.strictEqual(+client.selectedDb, 3)
|
||||||
assert(!client.options.port)
|
assert(!client._options.port)
|
||||||
assert.strictEqual(client.options.host, config.HOST[ip])
|
assert.strictEqual(client._options.host, config.HOST[ip])
|
||||||
client.on('ready', done)
|
client.on('ready', done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -201,7 +201,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
killConnection (client) {
|
killConnection (client) {
|
||||||
// Change the connection option to a non existing one and destroy the stream
|
// Change the connection option to a non existing one and destroy the stream
|
||||||
client.connectionOptions = {
|
client._connectionOptions = {
|
||||||
port: 65535,
|
port: 65535,
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
family: 4
|
family: 4
|
||||||
|
@@ -77,9 +77,9 @@ describe('The nodeRedis client', () => {
|
|||||||
assert.strictEqual(client2.selectedDb, 2)
|
assert.strictEqual(client2.selectedDb, 2)
|
||||||
assert(client.connected)
|
assert(client.connected)
|
||||||
assert(!client2.connected)
|
assert(!client2.connected)
|
||||||
for (const elem in client.options) {
|
for (const elem in client._options) {
|
||||||
if (client.options.hasOwnProperty(elem)) {
|
if (client._options.hasOwnProperty(elem)) {
|
||||||
assert.strictEqual(client2.options[elem], client.options[elem])
|
assert.strictEqual(client2._options[elem], client._options[elem])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client2.on('error', (err) => {
|
client2.on('error', (err) => {
|
||||||
@@ -101,13 +101,13 @@ describe('The nodeRedis client', () => {
|
|||||||
})
|
})
|
||||||
assert(client.connected)
|
assert(client.connected)
|
||||||
assert(!client2.connected)
|
assert(!client2.connected)
|
||||||
assert.strictEqual(client.options.noReadyCheck, undefined)
|
assert.strictEqual(client._options.noReadyCheck, undefined)
|
||||||
assert.strictEqual(client2.options.noReadyCheck, true)
|
assert.strictEqual(client2._options.noReadyCheck, true)
|
||||||
assert.notDeepEqual(client.options, client2.options)
|
assert.notDeepEqual(client._options, client2._options)
|
||||||
for (const elem in client.options) {
|
for (const elem in client._options) {
|
||||||
if (client.options.hasOwnProperty(elem)) {
|
if (client._options.hasOwnProperty(elem)) {
|
||||||
if (elem !== 'noReadyCheck') {
|
if (elem !== 'noReadyCheck') {
|
||||||
assert.strictEqual(client2.options[elem], client.options[elem])
|
assert.strictEqual(client2._options[elem], client._options[elem])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,17 +331,17 @@ describe('The nodeRedis client', () => {
|
|||||||
it('reconnects properly when monitoring', (done) => {
|
it('reconnects properly when monitoring', (done) => {
|
||||||
client.on('reconnecting', function onRecon (params) {
|
client.on('reconnecting', function onRecon (params) {
|
||||||
client.on('ready', function onReady () {
|
client.on('ready', function onReady () {
|
||||||
assert.strictEqual(client.monitoring, true, 'monitoring after reconnect')
|
assert.strictEqual(client._monitoring, true, 'monitoring after reconnect')
|
||||||
client.removeListener('ready', onReady)
|
client.removeListener('ready', onReady)
|
||||||
client.removeListener('reconnecting', onRecon)
|
client.removeListener('reconnecting', onRecon)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.strictEqual(client.monitoring, false, 'monitoring off at start')
|
assert.strictEqual(client._monitoring, false, 'monitoring off at start')
|
||||||
client.set('recon 1', 'one')
|
client.set('recon 1', 'one')
|
||||||
client.monitor().then((res) => {
|
client.monitor().then((res) => {
|
||||||
assert.strictEqual(client.monitoring, true, 'monitoring on after monitor()')
|
assert.strictEqual(client._monitoring, true, 'monitoring on after monitor()')
|
||||||
client.set('recon 2', 'two').then((res) => {
|
client.set('recon 2', 'two').then((res) => {
|
||||||
// Do not do this in normal programs. This is to simulate the server closing on us.
|
// Do not do this in normal programs. This is to simulate the server closing on us.
|
||||||
// For orderly shutdown in normal programs, do client.quit()
|
// For orderly shutdown in normal programs, do client.quit()
|
||||||
|
@@ -77,7 +77,7 @@ describe('publish/subscribe', () => {
|
|||||||
assert.strictEqual(typeof count, 'number')
|
assert.strictEqual(typeof count, 'number')
|
||||||
assert.strictEqual(--i, count)
|
assert.strictEqual(--i, count)
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
assert.deepStrictEqual(sub.subscriptionSet, {})
|
assert.deepStrictEqual(sub._subscriptionSet, {})
|
||||||
end()
|
end()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -20,7 +20,7 @@ describe('returnBuffers', () => {
|
|||||||
let i = 1
|
let i = 1
|
||||||
if (args[2].detectBuffers) {
|
if (args[2].detectBuffers) {
|
||||||
// Test if detectBuffer option was deactivated
|
// Test if detectBuffer option was deactivated
|
||||||
assert.strictEqual(client.options.detectBuffers, false)
|
assert.strictEqual(client._options.detectBuffers, false)
|
||||||
args[2].detectBuffers = false
|
args[2].detectBuffers = false
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ describe('TLS connection tests', () => {
|
|||||||
assert.strictEqual(client.emittedEnd, true)
|
assert.strictEqual(client.emittedEnd, true)
|
||||||
assert.strictEqual(client.connected, false)
|
assert.strictEqual(client.connected, false)
|
||||||
assert.strictEqual(client.ready, false)
|
assert.strictEqual(client.ready, false)
|
||||||
assert.strictEqual(client.closing, true)
|
assert.strictEqual(client._closing, true)
|
||||||
assert.strictEqual(time, connectTimeout)
|
assert.strictEqual(time, connectTimeout)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@@ -97,8 +97,8 @@ describe('TLS connection tests', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// verify connection is using TCP, not UNIX socket
|
// verify connection is using TCP, not UNIX socket
|
||||||
assert.strictEqual(client.connectionOptions.host, 'localhost')
|
assert.strictEqual(client._connectionOptions.host, 'localhost')
|
||||||
assert.strictEqual(client.connectionOptions.port, tlsPort)
|
assert.strictEqual(client._connectionOptions.port, tlsPort)
|
||||||
assert.strictEqual(client.address, `localhost:${tlsPort}`)
|
assert.strictEqual(client.address, `localhost:${tlsPort}`)
|
||||||
assert(client._stream.encrypted)
|
assert(client._stream.encrypted)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user