title: Golang Redis error on heroku
body: <p>I am having a hard time on this one because I cannot reproduce it locally. Intention originally was to test if a Redis connection is accessible from a go method if so continue else inform.</p>
  
  <p>In my code:</p>
  
  <pre><code>if os.Getenv("REDISTOGO_URL") != "" {
      host, password = parseRedistogoUrl()
  } else {
      host = "tcp:localhost:6379"
      password = ""
  }
  
  db := 0
  
  redis = godis.New(host, db, password)
  
  // Try to set a "dummy" value:
  err = redis.Set("INIT", time.Now().UTC())
  </code></pre>
  
  <p>With a Redis server available locally this executes without an error, but fails when on heroku.</p>
  
  <p>What makes the problem more interesting is that if the last line (with <code>err</code>) is commented out then the next <code>redis.Set</code> in the program succeeds, which indicates that the server is accessible later on, but not "just after" the instanciation. Any ideas on how I should resolve this? Is <code>godis.New(...)</code> running asynchronously?</p>
  
  <p>Update: This is the parsing function currently used from <a href="https://gist.github.com/TheDudeWithTheThing/6468746" rel="nofollow">https://gist.github.com/TheDudeWithTheThing/6468746</a>:</p>
  
  <pre><code>func ParseRedistogoUrl() (string, string) {
    redisUrl := os.Getenv("REDISTOGO_URL")
    redisInfo, _ := url.Parse(redisUrl)
    server := redisInfo.Host
    password := ""
    if redisInfo.User != nil {
      password, _ = redisInfo.User.Password()
    }
    return server, password
  }
  </code></pre>
  
  <p>Rewriting the same method with redigo and <a href="https://github.com/soveran/redisurl" rel="nofollow">https://github.com/soveran/redisurl</a>:</p>
  
  <pre><code>// Gets redis instance from configuration parameters or environment's REDISTOGO_URL.
  func redis_instance() (redis_con redis.Conn, err error) {
      if os.Getenv("REDISTOGO_URL") != "" {
          redis_con, err = redisurl.ConnectToURL(os.Getenv("REDISTOGO_URL"))
      } else {
          redis_con, err = redis.Dial("tcp", ":6379")
      }
  
      if err != nil {
          return
      }
  
      // Try to set a "dummy" value, panic if redis is not accessible.
      err = redis_con.Send("Set", "INIT", time.Now().UTC())
  
      return
  }
  </code></pre>
  
  <p>and from program's main:</p>
  
  <pre><code>redis, err := redis_instance()
  
  redis.Send("Set", "SOMETHING", "ELSE")
  
  if err != nil {
      log.Critical("Cannot access Redis server")
      log.Critical(fmt.Sprintf("%s", err))
      os.Exit(2)
  }
  </code></pre>
  
  <p>On logs I get the following output:</p>
  
  <p>2014-09-16T18:15:10.084908+00:00 app[web.1]: 2014/09/16 18:15:10 CRITICAL003 Cannot access Redis server<br>
  2014-09-16T18:15:10.084974+00:00 app[web.1]: 2014/09/16 18:15:10 CRITICAL004 Connection error 10942</p>
  
  <p>About redis access:</p>
  
  <pre><code>~ $ echo $REDISTOGO_URL
  redis://redistogo:47███████████@hoki.redistogo.com:10███/
  ~ $ ping hoki.redistogo.com
  bash: ping: command not found
  ~ $ nc hoki.redistogo.com 10███
  flushdb
  -NOAUTH Authentication required.
  AUTH 47███████████
  +OK
  get XXX
  $-1
  set XXX 2
  +OK
  get XXX
  $1
  2
  </code></pre>