From f0ae6642f91c2375a0becb7596060aab1ff27cf5 Mon Sep 17 00:00:00 2001 From: Jonas Dohse Date: Thu, 10 Jan 2013 15:35:15 +0000 Subject: [PATCH] Use first word of multi word commands Close #363. Signed-off-by: DTrejo --- README.md | 9 +++++++++ index.js | 4 +++- test.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46e7018c4b..aab10658a2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 4f920bc427..b6a0181952 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test.js b/test.js index 033bef03a2..ba801b56c7 100644 --- a/test.js +++ b/test.js @@ -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;