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);
}
}
* 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) {
}
/* -- 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;
}
#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 */
::redis::redis_read_reply $fd
}
+proc ::redis::__method__write {id fd buf} {
+ ::redis::redis_write $fd $buf
+}
+
+proc ::redis::__method__flush {id fd} {
+ flush $fd
+}
+
proc ::redis::__method__close {id fd} {
catch {close $fd}
catch {unset ::redis::fd($id)}
if {[dict exists $config port]} { set port [dict get $config port] }
# setup config dict
- dict set srv "config" $config_file
+ dict set srv "config_file" $config_file
+ dict set srv "config" $config
dict set srv "pid" $pid
dict set srv "host" $host
dict set srv "port" $port
after 10
}
- set client [redis $host $port]
- dict set srv "client" $client
-
- # select the right db when we don't have to authenticate
- if {![dict exists $config requirepass]} {
- $client select 9
- }
-
# append the server to the stack
lappend ::servers $srv
-
+
+ # connect client (after server dict is put on the stack)
+ reconnect
+
# execute provided block
set curnum $::testnum
if {![catch { uplevel 1 $code } err]} {
[srv $level "client"] {*}$args
}
+proc reconnect {args} {
+ set level [lindex $args 0]
+ if {[string length $level] == 0 || ![string is integer $level]} {
+ set level 0
+ }
+
+ set srv [lindex $::servers end+$level]
+ set host [dict get $srv "host"]
+ set port [dict get $srv "port"]
+ set config [dict get $srv "config"]
+ set client [redis $host $port]
+ dict set srv "client" $client
+
+ # select the right db when we don't have to authenticate
+ if {![dict exists $config "requirepass"]} {
+ $client select 9
+ }
+
+ # re-set $srv in the servers list
+ set ::servers [lreplace $::servers end+$level 1 $srv]
+}
+
proc redis_deferring_client {args} {
set level 0
if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {