Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Tcl client does not allow detecting EOF #531

Open
wojciechka opened this Issue · 0 comments

1 participant

@wojciechka

Currently it is not possible to detect EOF using the API - i.e. to reconnect whenever connection is lost, which is useful when listening for messages.

While using ping can be a good workaround, it still requires checking that the command exists/no longer exists. And usually detecting EOF can be done faster this way.

With change below it is possible to do:

set r [redis]
$r blocking 0
$r onclose reconnect_later

# (listen for channel)

Below is patch to enable it:

--- redis.tcl   2012-05-25 06:20:58.000000000 +0200
+++ redis.tcl   2012-05-31 21:09:52.068971000 +0200
@@ -44,6 +44,7 @@
     set ::redis::fd($id) $fd
     set ::redis::blocking($id) 1
     set ::redis::deferred($id) $defer
+    set ::redis::closecallback($id) ""
     ::redis::redis_reset_state $id
     interp alias {} ::redis::redisHandle$id {} ::redis::__dispatch__ $id
 }
@@ -84,6 +85,11 @@
     }
 }

+proc ::redis::__method__onclose {id fd command} {
+    set ::redis::closecallback($id) $command
+    return $command
+}
+
 proc ::redis::__method__blocking {id fd val} {
     set ::redis::blocking($id) $val
     fconfigure $fd -blocking $val
@@ -102,12 +108,17 @@
 }

 proc ::redis::__method__close {id fd} {
+    if {[string length $::redis::closecallback($id)] > 0} {
+        uplevel #0 $::redis::closecallback($id) [list ::redis::redisHandle$id]
+    }
+
     catch {close $fd}
     catch {unset ::redis::fd($id)}
     catch {unset ::redis::blocking($id)}
     catch {unset ::redis::state($id)}
     catch {unset ::redis::statestack($id)}
     catch {unset ::redis::callback($id)}
+    catch {unset ::redis::closecallback($id)}
     catch {interp alias {} ::redis::redisHandle$id {}}
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.