Skip to content

Commit

Permalink
Use first word of multi word commands
Browse files Browse the repository at this point in the history
Close redis#363.

Signed-off-by: DTrejo <[email protected]>
  • Loading branch information
Jonas Dohse authored and DTrejo committed Feb 24, 2013
1 parent 938c052 commit f0ae664
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ This will display:

`send command` is data sent into Redis and `on_data` is data received from Redis.

## Multi-word commands

To execute redis multi-word commands like `SCRIPT LOAD` or `CLIENT LIST` pass
the second word as first parameter:

client.script('load', 'return 1');
client.multi().script('load', 'return 1').exec(...);
client.multi([['script', 'load', 'return 1']]).exec(...);

## client.send_command(command_name, args, callback)

Used internally to send commands to Redis. For convenience, nearly all commands that are published on the Redis
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ commands = set_union(["get", "set", "setnx", "setex", "append", "strlen", "del",
"persist", "slaveof", "debug", "config", "subscribe", "unsubscribe", "psubscribe", "punsubscribe", "publish", "watch", "unwatch", "cluster",
"restore", "migrate", "dump", "object", "client", "eval", "evalsha"], require("./lib/commands"));

commands.forEach(function (command) {
commands.forEach(function (fullCommand) {
var command = fullCommand.split(' ')[0];

RedisClient.prototype[command] = function (args, callback) {
if (Array.isArray(args) && typeof callback === "function") {
return this.send_command(command, args, callback);
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ tests.EVAL_1 = function () {
}
};

tests.SCRIPT_LOAD = function() {
if (server_version_at_least(bclient, [2, 5, 0])) {
var name = "SCRIPT_LOAD",
command = "return 1",
commandSha = crypto.createHash('sha1').update(command).digest('hex');

bclient.script("load", command, function(err, result) {
assert.strictEqual(result.toString(), commandSha);
next(name);
});
} else {
console.log("Skipping " + name + " because server version isn't new enough.");
next(name);
}
};

tests.WATCH_MULTI = function () {
var name = 'WATCH_MULTI', multi;

Expand Down

0 comments on commit f0ae664

Please sign in to comment.