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

chore: refactor main code into smaller parts

This commit is contained in:
Ruben Bridgewater
2017-05-27 03:41:27 +02:00
parent be3976e8ba
commit 2aa3b68fc6
9 changed files with 205 additions and 190 deletions

27
lib/offlineCommand.js Normal file
View File

@@ -0,0 +1,27 @@
'use strict'
const Errors = require('redis-errors')
const utils = require('./utils')
const debug = require('./debug')
function offlineCommand (client, command) {
const commandName = command.command.toUpperCase()
if (client.closing || !client.enableOfflineQueue) {
const msg = client.closing === true
? 'The connection is already closed.'
: client._stream.writable === true
? 'The connection is not yet established and the offline queue is deactivated.'
: 'Stream not writeable.'
const err = new Errors.AbortError(`${commandName} can't be processed. ${msg}`)
err.code = 'NR_CLOSED'
err.command = commandName
err.args = command.args
utils.replyInOrder(client, command.callback, err)
} else {
debug('Queueing %s for next server connection.', commandName)
client.offlineQueue.push(command)
}
client.shouldBuffer = true
}
module.exports = offlineCommand