Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ca262a58
Commit
ca262a58
authored
Jun 16, 2014
by
antirez
Browse files
New features for CLIENT KILL.
parent
b7dd4518
Changes
2
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
ca262a58
...
...
@@ -1346,27 +1346,72 @@ void clientCommand(redisClient *c) {
redisClient *client;
if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
/* CLIENT LIST */
sds o = getAllClientsInfoString();
addReplyBulkCBuffer(c,o,sdslen(o));
sdsfree(o);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"kill"
)
&&
c
->
argc
==
3
)
{
} else if (!strcasecmp(c->argv[1]->ptr,"kill")) {
/* CLIENT KILL <ip:port>
* CLIENT KILL <attrib> <value> */
char *addr = NULL;
int type = -1;
uint64_t id = 0;
int killed = 0;
/* Parse arguments. */
if (c->argc == 3) {
addr = c->argv[2]->ptr;
} else if (c->argc == 4) {
if (!strcasecmp(c->argv[2]->ptr,"id")) {
long long tmp;
if (getLongLongFromObjectOrReply(c,c->argv[3],&tmp,NULL)
!= REDIS_OK) return;
id = tmp;
} else if (!strcasecmp(c->argv[2]->ptr,"type")) {
type = getClientTypeByName(c->argv[3]->ptr);
if (type == -1) {
addReplyErrorFormat(c,"Unknown client type '%s'",
(char*) c->argv[3]->ptr);
return;
}
} else if (!strcasecmp(c->argv[2]->ptr,"addr")) {
addr = c->argv[3]->ptr;
} else {
addReply(c,shared.syntaxerr);
return;
}
} else {
addReply(c,shared.syntaxerr);
return;
}
/* Iterate clients killing all the matching clients. */
listRewind(server.clients,&li);
while ((ln = listNext(&li)) != NULL) {
char
*
peerid
;
client = listNodeValue(ln);
peerid
=
getClientPeerId
(
client
);
if
(
strcmp
(
peerid
,
c
->
argv
[
2
]
->
ptr
)
==
0
)
{
addReply
(
c
,
shared
.
ok
);
if (addr && strcmp(getClientPeerId(client),addr) != 0) continue;
if (type != -1 && getClientType(client) != type) continue;
if (id != 0 && client->id != id) continue;
/* Kill it. */
if (c == client) {
client->flags |= REDIS_CLOSE_AFTER_REPLY;
} else {
freeClient(client);
}
return
;
}
killed++;
}
/* Reply according to old/new format. */
if (c->argc == 3) {
if (killed == 0)
addReplyError(c,"No such client");
else
addReply(c,shared.ok);
} else {
addReplyLongLong(c,killed);
}
} else if (!strcasecmp(c->argv[1]->ptr,"setname") && c->argc == 3) {
int j, len = sdslen(c->argv[2]->ptr);
char *p = c->argv[2]->ptr;
...
...
src/redis.h
View file @
ca262a58
...
...
@@ -1004,6 +1004,7 @@ void rewriteClientCommandArgument(redisClient *c, int i, robj *newval);
unsigned
long
getClientOutputBufferMemoryUsage
(
redisClient
*
c
);
void
freeClientsInAsyncFreeQueue
(
void
);
void
asyncCloseClientOnOutputBufferLimitReached
(
redisClient
*
c
);
int
getClientType
(
redisClient
*
c
);
int
getClientTypeByName
(
char
*
name
);
char
*
getClientTypeName
(
int
class
);
void
flushSlavesOutputBuffers
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment