title: Re-using Redigo connection instead of recreating it every time
body: <p>Connecting to Redigo and manipulating data inside a function is easy like butter, but the problem comes when you have to re-use its connection, obviously for performance/practicality reasons.</p>
  
  <p>Doing it inside a function like this works:</p>
  
  <pre><code>func main() {
  
      client, err := redis.Dial("tcp", ":6379")
      if err != nil {
          panic(err)
      }
      defer client.Close()
  
      client.Do("GET", "test:1")
  }
  </code></pre>
  
  <p>But bringing it outside doesn't:</p>
  
  <pre><code>var Client = redis.Dial("tcp", ":6379")
  defer Client.Close()
  
  func main() {
  
          Client.Do("GET", "test:1")
      }
  </code></pre>
  
  <p>With the following error(s) returned:</p>
  
  <pre><code>./main.go:1: multiple-value redis.Dial() in single-value context
  ./main.go:2: non-declaration statement outside function body
  </code></pre>
  
  <p>I've tried putting the connection as a <strong>const</strong>(ant), putting <strong>defer</strong> inside the main function to my dismay not working too.</p>
  
  <p>This is an even bigger concern as I have many other functions that have to communicate to Redis, but recreating the connection to Redis everytime seems silly.</p>
  
  <p>The Redigo API just shows how to create a <strong>Dial</strong> instance but doesn't go further by explaining how to re-use it.</p>
  
  <p>You may've been lost in my talk, but I wanted to put a bit of context here, so my clear and concise question is: <em>How do you go about re-using (not recreating everytime) a Redigo connection?</em></p>