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: refactor some code and remove obsolete variable
This commit is contained in:
@ -2,10 +2,8 @@
|
||||
|
||||
const Errors = require('redis-errors')
|
||||
const debug = require('./debug')
|
||||
var lazyConnect = function (client) {
|
||||
lazyConnect = require('./connect')
|
||||
lazyConnect(client)
|
||||
}
|
||||
const flushAndError = require('./flushAndError')
|
||||
const connect = require('./connect')
|
||||
|
||||
/**
|
||||
* @description Try connecting to a server again
|
||||
@ -27,7 +25,7 @@ function retryConnection (client, error) {
|
||||
|
||||
client.retryTotaltime += client.retryDelay
|
||||
client.attempts += 1
|
||||
lazyConnect(client)
|
||||
connect(client)
|
||||
client.retryTimer = null
|
||||
}
|
||||
|
||||
@ -51,18 +49,14 @@ function reconnect (client, why, error) {
|
||||
client.ready = false
|
||||
client.pubSubMode = 0
|
||||
|
||||
// since we are collapsing end and close, users don't expect to be called twice
|
||||
if (!client.emittedEnd) {
|
||||
client.emit('end')
|
||||
client.emittedEnd = true
|
||||
}
|
||||
client.emit('end')
|
||||
|
||||
if (why === 'timeout') {
|
||||
var message = 'Redis connection in broken state: connection timeout exceeded.'
|
||||
const err = new Errors.RedisError(message)
|
||||
// TODO: Find better error codes...
|
||||
err.code = 'CONNECTION_BROKEN'
|
||||
client.flushAndError(message, 'CONNECTION_BROKEN')
|
||||
flushAndError(client, message, 'CONNECTION_BROKEN')
|
||||
client.emit('error', err)
|
||||
client.end(false)
|
||||
return
|
||||
@ -71,7 +65,7 @@ function reconnect (client, why, error) {
|
||||
// If client is a requested shutdown, then don't retry
|
||||
if (client.closing) {
|
||||
debug('Connection ended by quit / end command, not retrying.')
|
||||
client.flushAndError('Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
flushAndError(client, 'Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
error
|
||||
})
|
||||
return
|
||||
@ -88,7 +82,7 @@ function reconnect (client, why, error) {
|
||||
if (client.retryDelay instanceof Error) {
|
||||
error = client.retryDelay
|
||||
}
|
||||
client.flushAndError('Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
flushAndError(client, 'Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
error
|
||||
})
|
||||
// TODO: Check if client is so smart
|
||||
@ -107,7 +101,7 @@ function reconnect (client, why, error) {
|
||||
// We could postpone writing to the stream until we connected again and fire the commands.
|
||||
// The commands in the pipelineQueue are also not uncertain. They never left the client.
|
||||
} else if (client.commandQueue.length !== 0 || client._pipelineQueue.length !== 0) {
|
||||
client.flushAndError('Redis connection lost and command aborted.', 'UNCERTAIN_STATE', {
|
||||
flushAndError(client, 'Redis connection lost and command aborted.', 'UNCERTAIN_STATE', {
|
||||
error,
|
||||
queues: ['commandQueue', '_pipelineQueue']
|
||||
})
|
||||
|
Reference in New Issue
Block a user