提交 674194ad 编写于 作者: A antirez

CLIENT KILL API modified.

Added a new SKIPME option that is true by default, that prevents the
client sending the command to be killed, unless SKIPME NO is sent.
上级 61d9a73d
...@@ -1325,35 +1325,52 @@ void clientCommand(redisClient *c) { ...@@ -1325,35 +1325,52 @@ void clientCommand(redisClient *c) {
sdsfree(o); sdsfree(o);
} else if (!strcasecmp(c->argv[1]->ptr,"kill")) { } else if (!strcasecmp(c->argv[1]->ptr,"kill")) {
/* CLIENT KILL <ip:port> /* CLIENT KILL <ip:port>
* CLIENT KILL <attrib> <value> */ * CLIENT KILL <option> [value] ... <option> [value] */
char *addr = NULL; char *addr = NULL;
int type = -1; int type = -1;
uint64_t id = 0; uint64_t id = 0;
int killed = 0; int skipme = 1;
int close_this_client = 0; int killed = 0, close_this_client = 0;
/* Parse arguments. */
if (c->argc == 3) { if (c->argc == 3) {
/* Old style syntax: CLIENT KILL <addr> */
addr = c->argv[2]->ptr; addr = c->argv[2]->ptr;
} else if (c->argc == 4) { } else if (c->argc > 3) {
if (!strcasecmp(c->argv[2]->ptr,"id")) { int i = 2; /* Next option index. */
long long tmp;
/* New style syntax: parse options. */
if (getLongLongFromObjectOrReply(c,c->argv[3],&tmp,NULL) while(i < c->argc) {
!= REDIS_OK) return; int moreargs = c->argc > i+1;
id = tmp;
} else if (!strcasecmp(c->argv[2]->ptr,"type")) { if (!strcasecmp(c->argv[i]->ptr,"id") && moreargs) {
type = getClientTypeByName(c->argv[3]->ptr); long long tmp;
if (type == -1) {
addReplyErrorFormat(c,"Unknown client type '%s'", if (getLongLongFromObjectOrReply(c,c->argv[i+1],&tmp,NULL)
(char*) c->argv[3]->ptr); != REDIS_OK) return;
id = tmp;
} else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) {
type = getClientTypeByName(c->argv[i+1]->ptr);
if (type == -1) {
addReplyErrorFormat(c,"Unknown client type '%s'",
(char*) c->argv[i+1]->ptr);
return;
}
} else if (!strcasecmp(c->argv[i]->ptr,"addr") && moreargs) {
addr = c->argv[i+1]->ptr;
} else if (!strcasecmp(c->argv[i]->ptr,"skipme") && moreargs) {
if (!strcasecmp(c->argv[i+1]->ptr,"yes")) {
skipme = 1;
} else if (!strcasecmp(c->argv[i+1]->ptr,"no")) {
skipme = 0;
} else {
addReply(c,shared.syntaxerr);
return;
}
} else {
addReply(c,shared.syntaxerr);
return; return;
} }
} else if (!strcasecmp(c->argv[2]->ptr,"addr")) { i += 2;
addr = c->argv[3]->ptr;
} else {
addReply(c,shared.syntaxerr);
return;
} }
} else { } else {
addReply(c,shared.syntaxerr); addReply(c,shared.syntaxerr);
...@@ -1367,6 +1384,7 @@ void clientCommand(redisClient *c) { ...@@ -1367,6 +1384,7 @@ void clientCommand(redisClient *c) {
if (addr && strcmp(getClientPeerId(client),addr) != 0) continue; if (addr && strcmp(getClientPeerId(client),addr) != 0) continue;
if (type != -1 && getClientType(client) != type) continue; if (type != -1 && getClientType(client) != type) continue;
if (id != 0 && client->id != id) continue; if (id != 0 && client->id != id) continue;
if (c == client && skipme) continue;
/* Kill it. */ /* Kill it. */
if (c == client) { if (c == client) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册