title: using external redis server for testing tcl scripts
body: <p>I am running Ubuntu 11.10.</p>
  
  <p>i am trying to run TCL test scripts using external redis server.</p>
  
  <p>using the following : </p>
  
  <pre><code>sb@sb-laptop:~/Redis/redis$ tclsh tests/test_helper.tcl --host 192.168.1.130 --port 6379
  </code></pre>
  
  <p>Getting the following error :</p>
  
  <pre><code>    Testing unit/type/list
  [exception]: Executing test client: couldn't open socket: connection refused.
  couldn't open socket: connection refused
      while executing
  "socket $server $port"
      (procedure "redis" line 2)
      invoked from within
  "redis $::host $::port"
      (procedure "start_server" line 9)
      invoked from within
  "start_server {tags {"protocol"}} {
      test "Handle an empty query" {
          reconnect
          r write "\r\n"
          r flush
          assert_equal "P..."
      (file "tests/unit/protocol.tcl" line 1)
      invoked from within
  "source $path"
      (procedure "execute_tests" line 4)
      invoked from within
  "execute_tests $data"
      (procedure "test_client_main" line 9)
      invoked from within
  "test_client_main $::test_server_port "
  </code></pre>
  
  <p>the <code>redis.conf</code> is set to default binding, but it is commented out.</p>
  
  <p>If this is possible, what i am doing wrong?</p>
  
  <p>Additional Information:</p>
  
  <p>Below is the tcl code that is responsible for starting the server</p>
  
  <pre><code>proc start_server {options {code undefined}} {
      # If we are runnign against an external server, we just push the
      # host/port pair in the stack the first time
      if {$::external} {
          if {[llength $::servers] == 0} {
              set srv {}
              dict set srv "host" $::host
              dict set srv "port" $::port
              set client [redis $::host $::port]
              dict set srv "client" $client
              $client select 9
  
              # append the server to the stack
              lappend ::servers $srv
          }
          uplevel 1 $code
          return
      }
  
      # setup defaults
      set baseconfig "default.conf"
      set overrides {}
      set tags {}
  
      # parse options
      foreach {option value} $options {
          switch $option {
              "config" {
                  set baseconfig $value }
              "overrides" {
                  set overrides $value }
              "tags" {
                  set tags $value
                  set ::tags [concat $::tags $value] }
              default {
                  error "Unknown option $option" }
          }
      }
  
      set data [split [exec cat "tests/assets/$baseconfig"] "\n"]
      set config {}
      foreach line $data {
          if {[string length $line] &gt; 0 &amp;&amp; [string index $line 0] ne "#"} {
              set elements [split $line " "]
              set directive [lrange $elements 0 0]
              set arguments [lrange $elements 1 end]
              dict set config $directive $arguments
          }
      }
  
      # use a different directory every time a server is started
      dict set config dir [tmpdir server]
  
      # start every server on a different port
      set ::port [find_available_port [expr {$::port+1}]]
      dict set config port $::port
  
      # apply overrides from global space and arguments
      foreach {directive arguments} [concat $::global_overrides $overrides] {
          dict set config $directive $arguments
      }
  
      # write new configuration to temporary file
      set config_file [tmpfile redis.conf]
      set fp [open $config_file w+]
      foreach directive [dict keys $config] {
          puts -nonewline $fp "$directive "
          puts $fp [dict get $config $directive]
      }
      close $fp
  
      set stdout [format "%s/%s" [dict get $config "dir"] "stdout"]
      set stderr [format "%s/%s" [dict get $config "dir"] "stderr"]
  
      if {$::valgrind} {
          exec valgrind --suppressions=src/valgrind.sup src/redis-server $config_file &gt; $stdout 2&gt; $stderr &amp;
      } else {
          exec src/redis-server $config_file &gt; $stdout 2&gt; $stderr &amp;
      }
  
      # check that the server actually started
      # ugly but tries to be as fast as possible...
      set retrynum 100
      set serverisup 0
  
      if {$::verbose} {
          puts -nonewline "=== ($tags) Starting server ${::host}:${::port} "
      }
  
      after 10
      if {$code ne "undefined"} {
          while {[incr retrynum -1]} {
              catch {
                  if {[ping_server $::host $::port]} {
                      set serverisup 1
                  }
              }
              if {$serverisup} break
              after 50
          }
      } else {
          set serverisup 1
      }
  
      if {$::verbose} {
          puts ""
      }
  
      if {!$serverisup} {
          error_and_quit $config_file [exec cat $stderr]
      }
  
      # find out the pid
      while {![info exists pid]} {
          regexp {\[(\d+)\]} [exec cat $stdout] _ pid
          after 100
      }
  
      # setup properties to be able to initialize a client object
      set host $::host
      set port $::port
      if {[dict exists $config bind]} { set host [dict get $config bind] }
      if {[dict exists $config port]} { set port [dict get $config port] }
  
      # setup config dict
      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
      dict set srv "stdout" $stdout
      dict set srv "stderr" $stderr
  
      # if a block of code is supplied, we wait for the server to become
      # available, create a client object and kill the server afterwards
      if {$code ne "undefined"} {
          set line [exec head -n1 $stdout]
          if {[string match {*already in use*} $line]} {
              error_and_quit $config_file $line
          }
  
          while 1 {
              # check that the server actually started and is ready for connections
              if {[exec cat $stdout | grep "ready to accept" | wc -l] &gt; 0} {
                  break
              }
              after 10
          }
  
          # append the server to the stack
          lappend ::servers $srv
  
          # connect client (after server dict is put on the stack)
          reconnect
  
          # execute provided block
          set num_tests $::num_tests
          if {[catch { uplevel 1 $code } error]} {
              set backtrace $::errorInfo
  
              # Kill the server without checking for leaks
              dict set srv "skipleaks" 1
              kill_server $srv
  
              # Print warnings from log
              puts [format "\nLogged warnings (pid %d):" [dict get $srv "pid"]]
              set warnings [warnings_from_file [dict get $srv "stdout"]]
              if {[string length $warnings] &gt; 0} {
                  puts "$warnings"
              } else {
                  puts "(none)"
              }
              puts ""
  
              error $error $backtrace
          }
  
          # Don't do the leak check when no tests were run
          if {$num_tests == $::num_tests} {
              dict set srv "skipleaks" 1
          }
  
          # pop the server object
          set ::servers [lrange $::servers 0 end-1]
  
          set ::tags [lrange $::tags 0 end-[llength $tags]]
          kill_server $srv
      } else {
          set ::tags [lrange $::tags 0 end-[llength $tags]]
          set _ $srv
      }
  }
  </code></pre>