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

chore: refactor main code base into smaller parts

This commit is contained in:
Ruben Bridgewater
2017-05-26 23:34:28 +02:00
parent 3065e2e7be
commit 1f179ef791
7 changed files with 322 additions and 291 deletions

View File

@@ -3,6 +3,8 @@
const tls = require('tls')
const Parser = require('redis-parser')
const net = require('net')
const reconnect = require('./reconnect')
const onConnect = require('./readyHandler')
const debug = require('./debug')
/**
@@ -77,7 +79,7 @@ function connect (client) {
// TODO: Investigate why this is not properly triggered
client._stream.setTimeout(client.connectTimeout, () => {
// Note: This is only tested if a internet connection is established
client.connectionGone('timeout')
reconnect(client, 'timeout')
})
}
@@ -86,7 +88,7 @@ function connect (client) {
client._stream.once(connectEvent, () => {
client._stream.removeAllListeners('timeout')
client.timesConnected++
client.onConnect()
onConnect(client)
})
client._stream.on('data', (bufferFromSocket) => {
@@ -105,11 +107,11 @@ function connect (client) {
})
client._stream.once('close', (hadError) => {
client.connectionGone('close')
reconnect(client, 'close')
})
client._stream.once('end', () => {
client.connectionGone('end')
reconnect(client, 'end')
})
client._stream.setNoDelay()