From acfe3675e3c5ab8ee2ca07642334d9468cfc4d39 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 22 Oct 2012 10:28:54 +0200 Subject: [PATCH] Differentiate SCRIPT KILL error replies. When calling SCRIPT KILL currently you can get two errors: * No script in timeout (busy) state. * The script already performed a write. It is useful to be able to distinguish the two errors, but right now both start with "ERR" prefix, so string matching (that is fragile) must be used. This commit introduces two different prefixes. -NOTBUSY and -UNKILLABLE respectively to reply with an error when no script is busy at the moment, and when the script already executed a write operation and can not be killed. --- src/scripting.c | 4 ++-- tests/unit/scripting.tcl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scripting.c b/src/scripting.c index 13f608e6..6f9ec2e8 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -977,9 +977,9 @@ void scriptCommand(redisClient *c) { sdsfree(sha); } else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"kill")) { if (server.lua_caller == NULL) { - addReplyError(c,"No scripts in execution right now."); + addReplySds(c,sdsnew("-NOTBUSY No scripts in execution right now.\r\n")); } else if (server.lua_write_dirty) { - addReplyError(c, "Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in an hard way using the SHUTDOWN NOSAVE command."); + addReplySds(c,sdsnew("-UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in an hard way using the SHUTDOWN NOSAVE command.\r\n")); } else { server.lua_kill = 1; addReply(c,shared.ok); diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 6dbdb6b6..f96d0fc6 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -301,7 +301,7 @@ start_server {tags {"scripting"}} { catch {r ping} e assert_match {BUSY*} $e catch {r script kill} e - assert_match {ERR*} $e + assert_match {UNKILLABLE*} $e catch {r ping} e assert_match {BUSY*} $e } -- 2.45.2