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

chore: refactor parts out of the index.js file

This commit is contained in:
Ruben Bridgewater
2017-05-26 18:45:52 +02:00
parent a3a74559da
commit 3065e2e7be
19 changed files with 271 additions and 281 deletions

View File

@@ -3,6 +3,7 @@
const debug = require('./debug')
const Multi = require('./multi')
const Command = require('./command')
const utils = require('./utils')
const noPasswordIsSet = /no password is set/
const RedisClient = require('../').RedisClient
@@ -21,11 +22,11 @@ const RedisClient = require('../').RedisClient
TODO: Implement hooks to replace this. Most of these things are perfect for hooks
********************************************************************************************/
function selectCallback (self, db) {
function selectCallback (client, db) {
return function (err, res) {
if (err === null) {
// Store db in this.selectDb to restore it on reconnect
self.selectedDb = db
client.selectedDb = db
}
return err || res
}
@@ -66,11 +67,11 @@ Multi.prototype.monitor = function monitor () {
return this
}
function quitCallback (self) {
function quitCallback (client) {
return function (err, res) {
if (self.stream.writable) {
if (client._stream.writable) {
// If the socket is still alive, kill it. This could happen if quit got a NR_CLOSED error code
self.stream.destroy()
client._stream.destroy()
}
if (err && err.code === 'NR_CLOSED') {
// Pretend the quit command worked properly in this case.
@@ -106,10 +107,10 @@ Multi.prototype.quit = function quit () {
return this
}
function infoCallback (self) {
function infoCallback (client) {
return function (err, res) {
if (err) {
self.serverInfo = {}
client.serverInfo = {}
return err
}
@@ -139,7 +140,7 @@ function infoCallback (self) {
})
}
// Expose info key/values to users
self.serverInfo = obj
client.serverInfo = obj
return res
}
}
@@ -156,11 +157,11 @@ Multi.prototype.info = function info (section) {
return this
}
function authCallback (self, pass) {
function authCallback (client, pass) {
return function (err, res) {
if (err) {
if (noPasswordIsSet.test(err.message)) {
self.warn('Warning: Redis server does not require a password, but a password was supplied.')
utils.warn(client, 'Warning: Redis server does not require a password, but a password was supplied.')
return 'OK' // TODO: Fix this
}
return err