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
102
lib/multi.js
102
lib/multi.js
@@ -7,25 +7,25 @@ var Command = require('./command');
|
||||
function Multi (client, args) {
|
||||
this._client = client;
|
||||
this.queue = new Queue();
|
||||
var command, tmp_args;
|
||||
var command, tmpArgs;
|
||||
if (args) { // Either undefined or an array. Fail hard if it's not an array
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
command = args[i][0];
|
||||
tmp_args = args[i].slice(1);
|
||||
tmpArgs = args[i].slice(1);
|
||||
if (Array.isArray(command)) {
|
||||
this[command[0]].apply(this, command.slice(1).concat(tmp_args));
|
||||
this[command[0]].apply(this, command.slice(1).concat(tmpArgs));
|
||||
} else {
|
||||
this[command].apply(this, tmp_args);
|
||||
this[command].apply(this, tmpArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pipeline_transaction_command (self, command_obj, index) {
|
||||
function pipelineTransactionCommand (self, commandObj, index) {
|
||||
// Queueing is done first, then the commands are executed
|
||||
var tmp = command_obj.callback;
|
||||
command_obj.callback = function (err, reply) {
|
||||
// Ignore the multi command. This is applied by node_redis and the user does not benefit by it
|
||||
var tmp = commandObj.callback;
|
||||
commandObj.callback = function (err, reply) {
|
||||
// Ignore the multi command. This is applied by nodeRedis and the user does not benefit by it
|
||||
if (err && index !== -1) {
|
||||
if (tmp) {
|
||||
tmp(err);
|
||||
@@ -34,22 +34,22 @@ function pipeline_transaction_command (self, command_obj, index) {
|
||||
self.errors.push(err);
|
||||
}
|
||||
// Keep track of who wants buffer responses:
|
||||
// By the time the callback is called the command_obj got the buffer_args attribute attached
|
||||
self.wants_buffers[index] = command_obj.buffer_args;
|
||||
command_obj.callback = tmp;
|
||||
// By the time the callback is called the commandObj got the bufferArgs attribute attached
|
||||
self.wantsBuffers[index] = commandObj.bufferArgs;
|
||||
commandObj.callback = tmp;
|
||||
};
|
||||
self._client.internal_send_command(command_obj);
|
||||
self._client.internalSendCommand(commandObj);
|
||||
}
|
||||
|
||||
Multi.prototype.exec_atomic = Multi.prototype.EXEC_ATOMIC = Multi.prototype.execAtomic = function exec_atomic (callback) {
|
||||
Multi.prototype.execAtomic = Multi.prototype.EXEC_ATOMIC = Multi.prototype.execAtomic = function execAtomic (callback) {
|
||||
if (this.queue.length < 2) {
|
||||
return this.exec_batch(callback);
|
||||
return this.execBatch(callback);
|
||||
}
|
||||
return this.exec(callback);
|
||||
};
|
||||
|
||||
function multi_callback (self, err, replies) {
|
||||
var i = 0, command_obj;
|
||||
function multiCallback (self, err, replies) {
|
||||
var i = 0, commandObj;
|
||||
|
||||
if (err) {
|
||||
err.errors = self.errors;
|
||||
@@ -63,22 +63,22 @@ function multi_callback (self, err, replies) {
|
||||
}
|
||||
|
||||
if (replies) {
|
||||
while (command_obj = self.queue.shift()) {
|
||||
while (commandObj = self.queue.shift()) {
|
||||
if (replies[i] instanceof Error) {
|
||||
var match = replies[i].message.match(utils.err_code);
|
||||
var match = replies[i].message.match(utils.errCode);
|
||||
// LUA script could return user errors that don't behave like all other errors!
|
||||
if (match) {
|
||||
replies[i].code = match[1];
|
||||
}
|
||||
replies[i].command = command_obj.command.toUpperCase();
|
||||
if (typeof command_obj.callback === 'function') {
|
||||
command_obj.callback(replies[i]);
|
||||
replies[i].command = commandObj.command.toUpperCase();
|
||||
if (typeof commandObj.callback === 'function') {
|
||||
commandObj.callback(replies[i]);
|
||||
}
|
||||
} else {
|
||||
// If we asked for strings, even in detect_buffers mode, then return strings:
|
||||
replies[i] = self._client.handle_reply(replies[i], command_obj.command, self.wants_buffers[i]);
|
||||
if (typeof command_obj.callback === 'function') {
|
||||
command_obj.callback(null, replies[i]);
|
||||
// If we asked for strings, even in detectBuffers mode, then return strings:
|
||||
replies[i] = self._client.handleReply(replies[i], commandObj.command, self.wantsBuffers[i]);
|
||||
if (typeof commandObj.callback === 'function') {
|
||||
commandObj.callback(null, replies[i]);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
@@ -90,37 +90,37 @@ function multi_callback (self, err, replies) {
|
||||
}
|
||||
}
|
||||
|
||||
Multi.prototype.exec_transaction = function exec_transaction (callback) {
|
||||
Multi.prototype.execTransaction = function execTransaction (callback) {
|
||||
if (this.monitoring || this._client.monitoring) {
|
||||
var err = new RangeError(
|
||||
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
|
||||
);
|
||||
err.command = 'EXEC';
|
||||
err.code = 'EXECABORT';
|
||||
return utils.reply_in_order(this._client, callback, err);
|
||||
return utils.replyInOrder(this._client, callback, err);
|
||||
}
|
||||
var self = this;
|
||||
var len = self.queue.length;
|
||||
self.errors = [];
|
||||
self.callback = callback;
|
||||
self._client.cork();
|
||||
self.wants_buffers = new Array(len);
|
||||
pipeline_transaction_command(self, new Command('multi', []), -1);
|
||||
self.wantsBuffers = new Array(len);
|
||||
pipelineTransactionCommand(self, new Command('multi', []), -1);
|
||||
// Drain queue, callback will catch 'QUEUED' or error
|
||||
for (var index = 0; index < len; index++) {
|
||||
// The commands may not be shifted off, since they are needed in the result handler
|
||||
pipeline_transaction_command(self, self.queue.get(index), index);
|
||||
pipelineTransactionCommand(self, self.queue.get(index), index);
|
||||
}
|
||||
|
||||
self._client.internal_send_command(new Command('exec', [], function (err, replies) {
|
||||
multi_callback(self, err, replies);
|
||||
self._client.internalSendCommand(new Command('exec', [], function (err, replies) {
|
||||
multiCallback(self, err, replies);
|
||||
}));
|
||||
self._client.uncork();
|
||||
return !self._client.should_buffer;
|
||||
return !self._client.shouldBuffer;
|
||||
};
|
||||
|
||||
function batch_callback (self, cb, i) {
|
||||
return function batch_callback (err, res) {
|
||||
function batchCallback (self, cb, i) {
|
||||
return function batchCallback (err, res) {
|
||||
if (err) {
|
||||
self.results[i] = err;
|
||||
// Add the position to the error
|
||||
@@ -132,24 +132,24 @@ function batch_callback (self, cb, i) {
|
||||
};
|
||||
}
|
||||
|
||||
Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = function exec_batch (callback) {
|
||||
Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.execBatch = function execBatch (callback) {
|
||||
var self = this;
|
||||
var len = self.queue.length;
|
||||
var index = 0;
|
||||
var command_obj;
|
||||
var commandObj;
|
||||
if (len === 0) {
|
||||
utils.reply_in_order(self._client, callback, null, []);
|
||||
return !self._client.should_buffer;
|
||||
utils.replyInOrder(self._client, callback, null, []);
|
||||
return !self._client.shouldBuffer;
|
||||
}
|
||||
self._client.cork();
|
||||
if (!callback) {
|
||||
while (command_obj = self.queue.shift()) {
|
||||
self._client.internal_send_command(command_obj);
|
||||
while (commandObj = self.queue.shift()) {
|
||||
self._client.internalSendCommand(commandObj);
|
||||
}
|
||||
self._client.uncork();
|
||||
return !self._client.should_buffer;
|
||||
return !self._client.shouldBuffer;
|
||||
}
|
||||
var callback_without_own_cb = function (err, res) {
|
||||
var callbackWithoutOwnCb = function (err, res) {
|
||||
if (err) {
|
||||
self.results.push(err);
|
||||
// Add the position to the error
|
||||
@@ -161,27 +161,27 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
|
||||
// Do not emit an error here. Otherwise each error would result in one emit.
|
||||
// The errors will be returned in the result anyway
|
||||
};
|
||||
var last_callback = function (cb) {
|
||||
var lastCallback = function (cb) {
|
||||
return function (err, res) {
|
||||
cb(err, res);
|
||||
callback(null, self.results);
|
||||
};
|
||||
};
|
||||
self.results = [];
|
||||
while (command_obj = self.queue.shift()) {
|
||||
if (typeof command_obj.callback === 'function') {
|
||||
command_obj.callback = batch_callback(self, command_obj.callback, index);
|
||||
while (commandObj = self.queue.shift()) {
|
||||
if (typeof commandObj.callback === 'function') {
|
||||
commandObj.callback = batchCallback(self, commandObj.callback, index);
|
||||
} else {
|
||||
command_obj.callback = callback_without_own_cb;
|
||||
commandObj.callback = callbackWithoutOwnCb;
|
||||
}
|
||||
if (typeof callback === 'function' && index === len - 1) {
|
||||
command_obj.callback = last_callback(command_obj.callback);
|
||||
commandObj.callback = lastCallback(commandObj.callback);
|
||||
}
|
||||
this._client.internal_send_command(command_obj);
|
||||
this._client.internalSendCommand(commandObj);
|
||||
index++;
|
||||
}
|
||||
self._client.uncork();
|
||||
return !self._client.should_buffer;
|
||||
return !self._client.shouldBuffer;
|
||||
};
|
||||
|
||||
module.exports = Multi;
|
||||
|
Reference in New Issue
Block a user