Return OK on QUIT

This commit is contained in:
Pieter Noordhuis
2010-10-13 11:25:40 +02:00
parent 9f1ae9abee
commit 941c9fa285
6 changed files with 51 additions and 13 deletions

View File

@ -546,6 +546,9 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
if (listLength(c->reply) == 0) {
c->sentlen = 0;
aeDeleteFileEvent(server.el,c->fd,AE_WRITABLE);
/* Close connection after entire reply has been sent. */
if (c->flags & REDIS_QUIT) freeClient(c);
}
}
@ -675,6 +678,10 @@ again:
* will try to reiterate. The following line will make it return asap. */
if (c->flags & REDIS_BLOCKED || c->flags & REDIS_IO_WAIT) return;
/* Never continue to process the input buffer after QUIT. After the output
* buffer is flushed (with the OK), the connection will be dropped. */
if (c->flags & REDIS_QUIT) return;
if (seeknewline && c->bulklen == -1) c->newline = strchr(c->querybuf,'\n');
seeknewline = 1;
if (c->bulklen == -1) {

View File

@ -962,10 +962,14 @@ int processCommand(redisClient *c) {
}
/* -- end of multi bulk commands processing -- */
/* The QUIT command is handled as a special case. Normal command
* procs are unable to close the client connection safely */
/* The QUIT command is handled separately. Normal command procs will
* go through checking for replication and QUIT will cause trouble
* when FORCE_REPLICATION is enabled and would be implemented in
* a regular command proc. */
redisAssert(!(c->flags & REDIS_QUIT));
if (!strcasecmp(c->argv[0]->ptr,"quit")) {
freeClient(c);
c->flags |= REDIS_QUIT;
addReply(c,shared.ok);
return 0;
}

View File

@ -144,6 +144,7 @@
#define REDIS_BLOCKED 16 /* The client is waiting in a blocking operation */
#define REDIS_IO_WAIT 32 /* The client is waiting for Virtual Memory I/O */
#define REDIS_DIRTY_CAS 64 /* Watched keys modified. EXEC will fail. */
#define REDIS_QUIT 128 /* Client will be disconnected after reply is sent */
/* Slave replication state - slave side */
#define REDIS_REPL_NONE 0 /* No active replication */