You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Merge pull request #835 from fintura/remove-stuff
Remove send_command safety checks. Fixes #629
This commit is contained in:
45
index.js
45
index.js
@@ -661,37 +661,26 @@ function Command(command, args, sub_command, buffer_args, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RedisClient.prototype.send_command = function (command, args, callback) {
|
RedisClient.prototype.send_command = function (command, args, callback) {
|
||||||
var arg, command_obj, i, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type;
|
var arg, command_obj, i, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0;
|
||||||
|
|
||||||
if (typeof command !== "string") {
|
// if (typeof callback === "function") {}
|
||||||
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
|
// probably the fastest way:
|
||||||
|
// client.command([arg1, arg2], cb); (straight passthrough)
|
||||||
|
// send_command(command, [arg1, arg2], cb);
|
||||||
|
if (args === undefined) {
|
||||||
|
args = [];
|
||||||
|
} else if (!callback && typeof args[args.length - 1] === "function") {
|
||||||
|
// most people find this variable argument length form more convenient, but it uses arguments, which is slower
|
||||||
|
// client.command(arg1, arg2, cb); (wraps up arguments into an array)
|
||||||
|
// send_command(command, [arg1, arg2, cb]);
|
||||||
|
// client.command(arg1, arg2); (callback is optional)
|
||||||
|
// send_command(command, [arg1, arg2]);
|
||||||
|
// client.command(arg1, arg2, undefined); (callback is undefined)
|
||||||
|
// send_command(command, [arg1, arg2, undefined]);
|
||||||
|
callback = args.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(args)) {
|
if (process.domain && callback) {
|
||||||
if (typeof callback === "function") {
|
|
||||||
// probably the fastest way:
|
|
||||||
// client.command([arg1, arg2], cb); (straight passthrough)
|
|
||||||
// send_command(command, [arg1, arg2], cb);
|
|
||||||
} else if (!callback) {
|
|
||||||
// most people find this variable argument length form more convenient, but it uses arguments, which is slower
|
|
||||||
// client.command(arg1, arg2, cb); (wraps up arguments into an array)
|
|
||||||
// send_command(command, [arg1, arg2, cb]);
|
|
||||||
// client.command(arg1, arg2); (callback is optional)
|
|
||||||
// send_command(command, [arg1, arg2]);
|
|
||||||
// client.command(arg1, arg2, undefined); (callback is undefined)
|
|
||||||
// send_command(command, [arg1, arg2, undefined]);
|
|
||||||
last_arg_type = typeof args[args.length - 1];
|
|
||||||
if (last_arg_type === "function" || last_arg_type === "undefined") {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error("send_command: last argument must be a callback or undefined");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error("send_command: second argument must be an array");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback && process.domain) {
|
|
||||||
callback = process.domain.bind(callback);
|
callback = process.domain.bind(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -117,6 +117,44 @@ describe("The node_redis client", function () {
|
|||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("send_command", function () {
|
||||||
|
|
||||||
|
it("omitting args should be fine in some cases", function (done) {
|
||||||
|
client.send_command("info", undefined, function(err, res) {
|
||||||
|
assert(/redis_version/.test(res));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("using another type as cb should just work as if there were no callback parameter", function (done) {
|
||||||
|
client.send_command('set', ['test', 'bla'], [true]);
|
||||||
|
client.get('test', function(err, res) {
|
||||||
|
assert.equal(res, 'bla');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("misusing the function should eventually throw (no command)", function (done) {
|
||||||
|
var mochaListener = helper.removeMochaListener();
|
||||||
|
|
||||||
|
process.once('uncaughtException', function (err) {
|
||||||
|
process.on('uncaughtException', mochaListener);
|
||||||
|
assert(/is not a function|toUpperCase/.test(err));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.send_command(true, 'info');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("misusing the function should eventually throw (wrong args)", function (done) {
|
||||||
|
client.send_command('info', false, function(err, res) {
|
||||||
|
assert.equal(err.message, 'ERR Protocol error: invalid multibulk length');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe("when redis closes unexpectedly", function () {
|
describe("when redis closes unexpectedly", function () {
|
||||||
it("reconnects and can retrieve the pre-existing data", function (done) {
|
it("reconnects and can retrieve the pre-existing data", function (done) {
|
||||||
client.on("reconnecting", function on_recon(params) {
|
client.on("reconnecting", function on_recon(params) {
|
||||||
|
Reference in New Issue
Block a user