1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00
This commit is contained in:
Ruben Bridgewater
2017-05-30 05:29:51 +02:00
parent ac26d0524d
commit 31fafd8b7c
6 changed files with 31 additions and 23 deletions

View File

@@ -74,8 +74,6 @@ class RedisClient extends EventEmitter {
} }
options.enableOfflineQueue = true 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(
@@ -85,12 +83,6 @@ class RedisClient extends EventEmitter {
) )
options.detectBuffers = false options.detectBuffers = false
} }
this._pipelineQueue = new Queue() // Holds all pipelined commands
this._pubSubMode = 0
this._subscriptionSet = {}
this._monitoring = false
this.messageBuffers = false
this._closing = false
if (options.authPass) { if (options.authPass) {
if (options.password) { if (options.password) {
throw new TypeError('The "password" and "authPass" option may not both be set at the same time.') throw new TypeError('The "password" and "authPass" option may not both be set at the same time.')
@@ -108,23 +100,38 @@ class RedisClient extends EventEmitter {
this.serverInfo = {} this.serverInfo = {}
this.connectionId = connectionId++ this.connectionId = connectionId++
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._strCache = ''
// Private Variables
// Pipelining
this._pipeline = false this._pipeline = false
this._strCache = ''
this._pipelineQueue = new Queue()
// Pub sub mode
this._subCommandsLeft = 0 this._subCommandsLeft = 0
this.timesConnected = 0 this._pubSubMode = 0
this.buffers = options.returnBuffers || options.detectBuffers this._subscriptionSet = {}
this._options = options this._subscribeChannels = []
this._messageBuffers = false
// Others
this._multi = false this._multi = false
this._reply = 'ON' // Returning replies is the default this._monitoring = false
this.retryStrategy = options.retryStrategy || function (options) { this._parserReturningBuffers = options.returnBuffers || options.detectBuffers
this._options = options
this._reply = 'ON'
this._retryStrategyProvided = !!options.retryStrategy
this._closing = false
this._timesConnected = 0
this._connectionOptions = cnxOptions
// Only used as timeout until redis has to be connected to redis until throwing an connection error
this._connectTimeout = +options.connectTimeout || 60 * 1000 // ms
this._retryStrategy = options.retryStrategy || function (options) {
// TODO: Find better defaults
if (options.attempt > 100) { if (options.attempt > 100) {
return return
} }
// reconnect after // reconnect after
return Math.min(options.attempt * 100, 3000) return Math.min(options.attempt * 100, 3000)
} }
this._retryStrategyProvided = !!options.retryStrategy
this._subscribeChannels = []
utils.setReconnectDefaults(this) utils.setReconnectDefaults(this)
// Init parser and connect // Init parser and connect
connect(this) connect(this)

View File

@@ -60,7 +60,7 @@ function createParser (client) {
connect(client) connect(client)
setImmediate(() => client.emit('error', err)) setImmediate(() => client.emit('error', err))
}, },
returnBuffers: client.buffers || client.messageBuffers, returnBuffers: client._parserReturningBuffers,
stringNumbers: client._options.stringNumbers || false stringNumbers: client._options.stringNumbers || false
}) })
} }

View File

@@ -19,7 +19,7 @@ function retryConnection (client, error) {
attempt: client.attempts, attempt: client.attempts,
error, error,
totalRetryTime: client.retryTotaltime, totalRetryTime: client.retryTotaltime,
timesConnected: client.timesConnected timesConnected: client._timesConnected
} }
client.emit('reconnecting', reconnectParams) client.emit('reconnecting', reconnectParams)
@@ -71,11 +71,11 @@ function reconnect (client, why, error) {
return return
} }
client.retryDelay = client.retryStrategy({ client.retryDelay = client._retryStrategy({
attempt: client.attempts, attempt: client.attempts,
error, error,
totalRetryTime: client.retryTotaltime, totalRetryTime: client.retryTotaltime,
timesConnected: client.timesConnected timesConnected: client._timesConnected
}) })
if (typeof client.retryDelay !== 'number') { if (typeof client.retryDelay !== 'number') {
var err var err

View File

@@ -42,7 +42,8 @@ function onResult (client, reply) {
// 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 === true) { if (client._monitoring === true) {
var replyStr var replyStr
if (client.buffers && Buffer.isBuffer(reply)) { // TODO: This could be further improved performance wise
if (client._parserReturningBuffers && Buffer.isBuffer(reply)) {
replyStr = reply.toString() replyStr = reply.toString()
} else { } else {
replyStr = reply replyStr = reply

View File

@@ -141,7 +141,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 === true) { if (client._options.detectBuffers === true && command.bufferArgs === false || client._messageBuffers === true) {
reply = replyToStrings(reply) reply = replyToStrings(reply)
} }

View File

@@ -125,7 +125,7 @@ if (process.platform !== 'win32') {
client = redis.createClient.apply(null, args) client = redis.createClient.apply(null, args)
client.auth(auth).catch(done) client.auth(auth).catch(done)
client.on('ready', function () { client.on('ready', function () {
if (this.timesConnected < 3) { if (this._timesConnected < 3) {
let interval = setInterval(() => { let interval = setInterval(() => {
if (client.commandQueue.length !== 0) { if (client.commandQueue.length !== 0) {
return return