From: antirez Date: Mon, 22 Oct 2012 08:28:54 +0000 (+0200) Subject: Differentiate SCRIPT KILL error replies. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/ab551808832a9f3097861a706b2c2f57302a3992 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. --- 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 }