You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Remove snack_case and always use camelCase
This commit is contained in:
committed by
Ruben Bridgewater
parent
a86c998a64
commit
28afc33c9a
@@ -4,7 +4,7 @@ var utils = require('./utils');
|
||||
var debug = require('./debug');
|
||||
var Multi = require('./multi');
|
||||
var Command = require('./command');
|
||||
var no_password_is_set = /no password is set/;
|
||||
var noPasswordIsSet = /no password is set/;
|
||||
var loading = /LOADING/;
|
||||
var RedisClient = require('../').RedisClient;
|
||||
|
||||
@@ -14,7 +14,7 @@ var RedisClient = require('../').RedisClient;
|
||||
The callback may be hooked as needed. The same does not apply to the rest of the function.
|
||||
State should not be set outside of the callback if not absolutly necessary.
|
||||
This is important to make sure it works the same as single command or in a multi context.
|
||||
To make sure everything works with the offline queue use the "call_on_write" function.
|
||||
To make sure everything works with the offline queue use the "callOnWrite" function.
|
||||
This is going to be executed while writing to the stream.
|
||||
|
||||
TODO: Implement individal command generation as soon as possible to prevent divergent code
|
||||
@@ -23,7 +23,7 @@ var RedisClient = require('../').RedisClient;
|
||||
|
||||
RedisClient.prototype.multi = RedisClient.prototype.MULTI = function multi (args) {
|
||||
var multi = new Multi(this, args);
|
||||
multi.exec = multi.EXEC = multi.exec_transaction;
|
||||
multi.exec = multi.EXEC = multi.execTransaction;
|
||||
return multi;
|
||||
};
|
||||
|
||||
@@ -32,45 +32,45 @@ RedisClient.prototype.batch = RedisClient.prototype.BATCH = function batch (args
|
||||
return new Multi(this, args);
|
||||
};
|
||||
|
||||
function select_callback (self, db, callback) {
|
||||
function selectCallback (self, db, callback) {
|
||||
return function (err, res) {
|
||||
if (err === null) {
|
||||
// Store db in this.select_db to restore it on reconnect
|
||||
self.selected_db = db;
|
||||
// Store db in this.selectDb to restore it on reconnect
|
||||
self.selectedDb = db;
|
||||
}
|
||||
utils.callback_or_emit(self, callback, err, res);
|
||||
utils.callbackOrEmit(self, callback, err, res);
|
||||
};
|
||||
}
|
||||
|
||||
RedisClient.prototype.select = RedisClient.prototype.SELECT = function select (db, callback) {
|
||||
return this.internal_send_command(new Command('select', [db], select_callback(this, db, callback)));
|
||||
return this.internalSendCommand(new Command('select', [db], selectCallback(this, db, callback)));
|
||||
};
|
||||
|
||||
Multi.prototype.select = Multi.prototype.SELECT = function select (db, callback) {
|
||||
this.queue.push(new Command('select', [db], select_callback(this._client, db, callback)));
|
||||
this.queue.push(new Command('select', [db], selectCallback(this._client, db, callback)));
|
||||
return this;
|
||||
};
|
||||
|
||||
RedisClient.prototype.monitor = RedisClient.prototype.MONITOR = function monitor (callback) {
|
||||
// Use a individual command, as this is a special case that does not has to be checked for any other command
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// Activating monitor mode has to happen before Redis returned the callback. The monitor result is returned first.
|
||||
// Therefore we expect the command to be properly processed. If this is not the case, it's not an issue either.
|
||||
self.monitoring = true;
|
||||
};
|
||||
return this.internal_send_command(new Command('monitor', [], callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('monitor', [], callback, callOnWrite));
|
||||
};
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.monitor = Multi.prototype.MONITOR = function monitor (callback) {
|
||||
// Use a individual command, as this is a special case that does not has to be checked for any other command
|
||||
if (this.exec !== this.exec_transaction) {
|
||||
if (this.exec !== this.execTransaction) {
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
self._client.monitoring = true;
|
||||
};
|
||||
this.queue.push(new Command('monitor', [], callback, call_on_write));
|
||||
this.queue.push(new Command('monitor', [], callback, callOnWrite));
|
||||
return this;
|
||||
}
|
||||
// Set multi monitoring to indicate the exec that it should abort
|
||||
@@ -79,7 +79,7 @@ Multi.prototype.monitor = Multi.prototype.MONITOR = function monitor (callback)
|
||||
return this;
|
||||
};
|
||||
|
||||
function quit_callback (self, callback) {
|
||||
function quitCallback (self, callback) {
|
||||
return function (err, res) {
|
||||
if (err && err.code === 'NR_CLOSED') {
|
||||
// Pretent the quit command worked properly in this case.
|
||||
@@ -90,7 +90,7 @@ function quit_callback (self, callback) {
|
||||
err = null;
|
||||
res = 'OK';
|
||||
}
|
||||
utils.callback_or_emit(self, callback, err, res);
|
||||
utils.callbackOrEmit(self, callback, err, res);
|
||||
if (self.stream.writable) {
|
||||
// If the socket is still alive, kill it. This could happen if quit got a NR_CLOSED error code
|
||||
self.stream.destroy();
|
||||
@@ -101,40 +101,40 @@ function quit_callback (self, callback) {
|
||||
RedisClient.prototype.QUIT = RedisClient.prototype.quit = function quit (callback) {
|
||||
// TODO: Consider this for v.3
|
||||
// Allow the quit command to be fired as soon as possible to prevent it landing in the offline queue.
|
||||
// this.ready = this.offline_queue.length === 0;
|
||||
var backpressure_indicator = this.internal_send_command(new Command('quit', [], quit_callback(this, callback)));
|
||||
// this.ready = this.offlineQueue.length === 0;
|
||||
var backpressureIndicator = this.internalSendCommand(new Command('quit', [], quitCallback(this, callback)));
|
||||
// Calling quit should always end the connection, no matter if there's a connection or not
|
||||
this.closing = true;
|
||||
this.ready = false;
|
||||
return backpressure_indicator;
|
||||
return backpressureIndicator;
|
||||
};
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.QUIT = Multi.prototype.quit = function quit (callback) {
|
||||
var self = this._client;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// If called in a multi context, we expect redis is available
|
||||
self.closing = true;
|
||||
self.ready = false;
|
||||
};
|
||||
this.queue.push(new Command('quit', [], quit_callback(self, callback), call_on_write));
|
||||
this.queue.push(new Command('quit', [], quitCallback(self, callback), callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
||||
function info_callback (self, callback) {
|
||||
function infoCallback (self, callback) {
|
||||
return function (err, res) {
|
||||
if (res) {
|
||||
var obj = {};
|
||||
var lines = res.toString().split('\r\n');
|
||||
var line, parts, sub_parts;
|
||||
var line, parts, subParts;
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
parts = lines[i].split(':');
|
||||
if (parts[1]) {
|
||||
if (parts[0].indexOf('db') === 0) {
|
||||
sub_parts = parts[1].split(',');
|
||||
subParts = parts[1].split(',');
|
||||
obj[parts[0]] = {};
|
||||
while (line = sub_parts.pop()) {
|
||||
while (line = subParts.pop()) {
|
||||
line = line.split('=');
|
||||
obj[parts[0]][line[0]] = +line[1];
|
||||
}
|
||||
@@ -150,15 +150,15 @@ function info_callback (self, callback) {
|
||||
});
|
||||
}
|
||||
// Expose info key/vals to users
|
||||
self.server_info = obj;
|
||||
self.serverInfo = obj;
|
||||
} else {
|
||||
self.server_info = {};
|
||||
self.serverInfo = {};
|
||||
}
|
||||
utils.callback_or_emit(self, callback, err, res);
|
||||
utils.callbackOrEmit(self, callback, err, res);
|
||||
};
|
||||
}
|
||||
|
||||
// Store info in this.server_info after each call
|
||||
// Store info in this.serverInfo after each call
|
||||
RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section, callback) {
|
||||
var args = [];
|
||||
if (typeof section === 'function') {
|
||||
@@ -166,7 +166,7 @@ RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section
|
||||
} else if (section !== undefined) {
|
||||
args = Array.isArray(section) ? section : [section];
|
||||
}
|
||||
return this.internal_send_command(new Command('info', args, info_callback(this, callback)));
|
||||
return this.internalSendCommand(new Command('info', args, infoCallback(this, callback)));
|
||||
};
|
||||
|
||||
Multi.prototype.info = Multi.prototype.INFO = function info (section, callback) {
|
||||
@@ -176,14 +176,14 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
|
||||
} else if (section !== undefined) {
|
||||
args = Array.isArray(section) ? section : [section];
|
||||
}
|
||||
this.queue.push(new Command('info', args, info_callback(this._client, callback)));
|
||||
this.queue.push(new Command('info', args, infoCallback(this._client, callback)));
|
||||
return this;
|
||||
};
|
||||
|
||||
function auth_callback (self, pass, callback) {
|
||||
function authCallback (self, pass, callback) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
if (no_password_is_set.test(err.message)) {
|
||||
if (noPasswordIsSet.test(err.message)) {
|
||||
self.warn('Warning: Redis server does not require a password, but a password was supplied.');
|
||||
err = null;
|
||||
res = 'OK';
|
||||
@@ -196,29 +196,29 @@ function auth_callback (self, pass, callback) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
utils.callback_or_emit(self, callback, err, res);
|
||||
utils.callbackOrEmit(self, callback, err, res);
|
||||
};
|
||||
}
|
||||
|
||||
RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, callback) {
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connectionId);
|
||||
|
||||
// Stash auth for connect and reconnect.
|
||||
this.auth_pass = pass;
|
||||
this.authPass = pass;
|
||||
var ready = this.ready;
|
||||
this.ready = ready || this.offline_queue.length === 0;
|
||||
var tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, callback)));
|
||||
this.ready = ready || this.offlineQueue.length === 0;
|
||||
var tmp = this.internalSendCommand(new Command('auth', [pass], authCallback(this, pass, callback)));
|
||||
this.ready = ready;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.auth = Multi.prototype.AUTH = function auth (pass, callback) {
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connectionId);
|
||||
|
||||
// Stash auth for connect and reconnect.
|
||||
this.auth_pass = pass;
|
||||
this.queue.push(new Command('auth', [pass], auth_callback(this._client, callback)));
|
||||
this.authPass = pass;
|
||||
this.queue.push(new Command('auth', [pass], authCallback(this._client, callback)));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -253,18 +253,18 @@ RedisClient.prototype.client = RedisClient.prototype.CLIENT = function client ()
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var call_on_write = undefined;
|
||||
var callOnWrite = undefined;
|
||||
// CLIENT REPLY ON|OFF|SKIP
|
||||
/* istanbul ignore next: TODO: Remove this as soon as Travis runs Redis 3.2 */
|
||||
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
|
||||
var reply_on_off = arr[1].toString().toUpperCase();
|
||||
if (reply_on_off === 'ON' || reply_on_off === 'OFF' || reply_on_off === 'SKIP') {
|
||||
call_on_write = function () {
|
||||
self.reply = reply_on_off;
|
||||
var replyOnOff = arr[1].toString().toUpperCase();
|
||||
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
||||
callOnWrite = function () {
|
||||
self.reply = replyOnOff;
|
||||
};
|
||||
}
|
||||
}
|
||||
return this.internal_send_command(new Command('client', arr, callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('client', arr, callback, callOnWrite));
|
||||
};
|
||||
|
||||
Multi.prototype.client = Multi.prototype.CLIENT = function client () {
|
||||
@@ -298,18 +298,18 @@ Multi.prototype.client = Multi.prototype.CLIENT = function client () {
|
||||
}
|
||||
}
|
||||
var self = this._client;
|
||||
var call_on_write = undefined;
|
||||
var callOnWrite = undefined;
|
||||
// CLIENT REPLY ON|OFF|SKIP
|
||||
/* istanbul ignore next: TODO: Remove this as soon as Travis runs Redis 3.2 */
|
||||
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
|
||||
var reply_on_off = arr[1].toString().toUpperCase();
|
||||
if (reply_on_off === 'ON' || reply_on_off === 'OFF' || reply_on_off === 'SKIP') {
|
||||
call_on_write = function () {
|
||||
self.reply = reply_on_off;
|
||||
var replyOnOff = arr[1].toString().toUpperCase();
|
||||
if (replyOnOff === 'ON' || replyOnOff === 'OFF' || replyOnOff === 'SKIP') {
|
||||
callOnWrite = function () {
|
||||
self.reply = replyOnOff;
|
||||
};
|
||||
}
|
||||
}
|
||||
this.queue.push(new Command('client', arr, callback, call_on_write));
|
||||
this.queue.push(new Command('client', arr, callback, callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -349,7 +349,7 @@ RedisClient.prototype.hmset = RedisClient.prototype.HMSET = function hmset () {
|
||||
arr[i] = arguments[i];
|
||||
}
|
||||
}
|
||||
return this.internal_send_command(new Command('hmset', arr, callback));
|
||||
return this.internalSendCommand(new Command('hmset', arr, callback));
|
||||
};
|
||||
|
||||
Multi.prototype.hmset = Multi.prototype.HMSET = function hmset () {
|
||||
@@ -413,10 +413,10 @@ RedisClient.prototype.subscribe = RedisClient.prototype.SUBSCRIBE = function sub
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
var callOnWrite = function () {
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
return this.internal_send_command(new Command('subscribe', arr, callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('subscribe', arr, callback, callOnWrite));
|
||||
};
|
||||
|
||||
Multi.prototype.subscribe = Multi.prototype.SUBSCRIBE = function subscribe () {
|
||||
@@ -440,10 +440,10 @@ Multi.prototype.subscribe = Multi.prototype.SUBSCRIBE = function subscribe () {
|
||||
}
|
||||
}
|
||||
var self = this._client;
|
||||
var call_on_write = function () {
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
var callOnWrite = function () {
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
this.queue.push(new Command('subscribe', arr, callback, call_on_write));
|
||||
this.queue.push(new Command('subscribe', arr, callback, callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -468,11 +468,11 @@ RedisClient.prototype.unsubscribe = RedisClient.prototype.UNSUBSCRIBE = function
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
return this.internal_send_command(new Command('unsubscribe', arr, callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('unsubscribe', arr, callback, callOnWrite));
|
||||
};
|
||||
|
||||
Multi.prototype.unsubscribe = Multi.prototype.UNSUBSCRIBE = function unsubscribe () {
|
||||
@@ -496,11 +496,11 @@ Multi.prototype.unsubscribe = Multi.prototype.UNSUBSCRIBE = function unsubscribe
|
||||
}
|
||||
}
|
||||
var self = this._client;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
this.queue.push(new Command('unsubscribe', arr, callback, call_on_write));
|
||||
this.queue.push(new Command('unsubscribe', arr, callback, callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -525,10 +525,10 @@ RedisClient.prototype.psubscribe = RedisClient.prototype.PSUBSCRIBE = function p
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
var callOnWrite = function () {
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
return this.internal_send_command(new Command('psubscribe', arr, callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('psubscribe', arr, callback, callOnWrite));
|
||||
};
|
||||
|
||||
Multi.prototype.psubscribe = Multi.prototype.PSUBSCRIBE = function psubscribe () {
|
||||
@@ -552,10 +552,10 @@ Multi.prototype.psubscribe = Multi.prototype.PSUBSCRIBE = function psubscribe ()
|
||||
}
|
||||
}
|
||||
var self = this._client;
|
||||
var call_on_write = function () {
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
var callOnWrite = function () {
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
this.queue.push(new Command('psubscribe', arr, callback, call_on_write));
|
||||
this.queue.push(new Command('psubscribe', arr, callback, callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -580,11 +580,11 @@ RedisClient.prototype.punsubscribe = RedisClient.prototype.PUNSUBSCRIBE = functi
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
return this.internal_send_command(new Command('punsubscribe', arr, callback, call_on_write));
|
||||
return this.internalSendCommand(new Command('punsubscribe', arr, callback, callOnWrite));
|
||||
};
|
||||
|
||||
Multi.prototype.punsubscribe = Multi.prototype.PUNSUBSCRIBE = function punsubscribe () {
|
||||
@@ -608,10 +608,10 @@ Multi.prototype.punsubscribe = Multi.prototype.PUNSUBSCRIBE = function punsubscr
|
||||
}
|
||||
}
|
||||
var self = this._client;
|
||||
var call_on_write = function () {
|
||||
var callOnWrite = function () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
self.pub_sub_mode = self.pub_sub_mode || self.command_queue.length + 1;
|
||||
self.pubSubMode = self.pubSubMode || self.commandQueue.length + 1;
|
||||
};
|
||||
this.queue.push(new Command('punsubscribe', arr, callback, call_on_write));
|
||||
this.queue.push(new Command('punsubscribe', arr, callback, callOnWrite));
|
||||
return this;
|
||||
};
|
||||
|
Reference in New Issue
Block a user