mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
New features for CLIENT KILL.
This commit is contained in:
parent
f26f79ea37
commit
e7affd266c
@ -1346,27 +1346,72 @@ void clientCommand(redisClient *c) {
|
|||||||
redisClient *client;
|
redisClient *client;
|
||||||
|
|
||||||
if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
|
if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
|
||||||
|
/* CLIENT LIST */
|
||||||
sds o = getAllClientsInfoString();
|
sds o = getAllClientsInfoString();
|
||||||
addReplyBulkCBuffer(c,o,sdslen(o));
|
addReplyBulkCBuffer(c,o,sdslen(o));
|
||||||
sdsfree(o);
|
sdsfree(o);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"kill") && c->argc == 3) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"kill")) {
|
||||||
listRewind(server.clients,&li);
|
/* CLIENT KILL <ip:port>
|
||||||
while ((ln = listNext(&li)) != NULL) {
|
* CLIENT KILL <attrib> <value> */
|
||||||
char *peerid;
|
char *addr = NULL;
|
||||||
|
int type = -1;
|
||||||
|
uint64_t id = 0;
|
||||||
|
int killed = 0;
|
||||||
|
|
||||||
client = listNodeValue(ln);
|
/* Parse arguments. */
|
||||||
peerid = getClientPeerId(client);
|
if (c->argc == 3) {
|
||||||
if (strcmp(peerid,c->argv[2]->ptr) == 0) {
|
addr = c->argv[2]->ptr;
|
||||||
addReply(c,shared.ok);
|
} else if (c->argc == 4) {
|
||||||
if (c == client) {
|
if (!strcasecmp(c->argv[2]->ptr,"id")) {
|
||||||
client->flags |= REDIS_CLOSE_AFTER_REPLY;
|
long long tmp;
|
||||||
} else {
|
|
||||||
freeClient(client);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
addReply(c,shared.syntaxerr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Iterate clients killing all the matching clients. */
|
||||||
|
listRewind(server.clients,&li);
|
||||||
|
while ((ln = listNext(&li)) != NULL) {
|
||||||
|
client = listNodeValue(ln);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
addReplyError(c,"No such client");
|
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"setname") && c->argc == 3) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"setname") && c->argc == 3) {
|
||||||
int j, len = sdslen(c->argv[2]->ptr);
|
int j, len = sdslen(c->argv[2]->ptr);
|
||||||
char *p = c->argv[2]->ptr;
|
char *p = c->argv[2]->ptr;
|
||||||
|
@ -1004,6 +1004,7 @@ void rewriteClientCommandArgument(redisClient *c, int i, robj *newval);
|
|||||||
unsigned long getClientOutputBufferMemoryUsage(redisClient *c);
|
unsigned long getClientOutputBufferMemoryUsage(redisClient *c);
|
||||||
void freeClientsInAsyncFreeQueue(void);
|
void freeClientsInAsyncFreeQueue(void);
|
||||||
void asyncCloseClientOnOutputBufferLimitReached(redisClient *c);
|
void asyncCloseClientOnOutputBufferLimitReached(redisClient *c);
|
||||||
|
int getClientType(redisClient *c);
|
||||||
int getClientTypeByName(char *name);
|
int getClientTypeByName(char *name);
|
||||||
char *getClientTypeName(int class);
|
char *getClientTypeName(int class);
|
||||||
void flushSlavesOutputBuffers(void);
|
void flushSlavesOutputBuffers(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user