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 #136 from bobrik/callback-fixes
added ability to pass undefined instead of callback
This commit is contained in:
10
index.js
10
index.js
@@ -551,7 +551,7 @@ function Command(command, args, sub_command, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RedisClient.prototype.send_command = function (command, args, callback) {
|
RedisClient.prototype.send_command = function (command, args, callback) {
|
||||||
var arg, this_args, command_obj, i, il, elem_count, stream = this.stream, buffer_args, command_str = "", buffered_writes = 0;
|
var arg, this_args, command_obj, i, il, elem_count, stream = this.stream, buffer_args, command_str = "", buffered_writes = 0, last_arg_type;
|
||||||
|
|
||||||
if (typeof command !== "string") {
|
if (typeof command !== "string") {
|
||||||
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
|
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
|
||||||
@@ -568,9 +568,11 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
|||||||
// send_command(command, [arg1, arg2, cb]);
|
// send_command(command, [arg1, arg2, cb]);
|
||||||
// client.command(arg1, arg2); (callback is optional)
|
// client.command(arg1, arg2); (callback is optional)
|
||||||
// send_command(command, [arg1, arg2]);
|
// send_command(command, [arg1, arg2]);
|
||||||
if (typeof args[args.length - 1] === "function") {
|
// client.command(arg1, arg2, undefined); (callback is undefined)
|
||||||
callback = args[args.length - 1];
|
// send_command(command, [arg1, arg2, undefined]);
|
||||||
args.length -= 1;
|
last_arg_type = typeof args[args.length - 1];
|
||||||
|
if (last_arg_type === "function" || last_arg_type === "undefined") {
|
||||||
|
callback = args.pop();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("send_command: last argument must be a callback or undefined");
|
throw new Error("send_command: last argument must be a callback or undefined");
|
||||||
|
14
test.js
14
test.js
@@ -1210,6 +1210,20 @@ tests.TTL = function () {
|
|||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tests.OPTIONAL_CALLBACK = function() {
|
||||||
|
var name = "OPTIONAL_CALLBACK";
|
||||||
|
client.del("op_cb1");
|
||||||
|
client.set("op_cb1", "x");
|
||||||
|
client.get("op_cb1", last(name, require_string("x", name)));
|
||||||
|
};
|
||||||
|
|
||||||
|
tests.OPTIONAL_CALLBACK_UNDEFINED = function() {
|
||||||
|
var name = "OPTIONAL_CALLBACK_UNDEFINED";
|
||||||
|
client.del("op_cb2");
|
||||||
|
client.set("op_cb2", "y", undefined);
|
||||||
|
client.get("op_cb2", last(name, require_string("y", name)));
|
||||||
|
}
|
||||||
|
|
||||||
all_tests = Object.keys(tests);
|
all_tests = Object.keys(tests);
|
||||||
all_start = new Date();
|
all_start = new Date();
|
||||||
test_count = 0;
|
test_count = 0;
|
||||||
|
Reference in New Issue
Block a user