Skip to content

Instantly share code, notes, and snippets.

@freeformz
Last active January 30, 2017 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freeformz/92881099cd525cb926df76bd0576b138 to your computer and use it in GitHub Desktop.
Save freeformz/92881099cd525cb926df76bd0576b138 to your computer and use it in GitHub Desktop.

Connecting in Go

Use the redigo or redis package in your application.

$ go get github.com/garyburd/redigo/redis 
$ # OR
$ go get gopkg.in/redis.v5

Import the package of choice in your *.go files.

...
import "github.com/garyburd/redigo/redis"
// OR
import "gopkg.in/redis.v5"
...

Use a supported vendoring tool to record and save your dependencies.

govendor

$ govendor fetch github.com/garyburd/redigo/redis
$ # OR
$ govendor fetch gopkg.in/redis.v5

godep

$ godep save

GB

$ gb vendor fetch github.com/garyburd/redigo/redi
$ # OR
$ gb vendor fetch gopkg.in/redis.v5

Connect to Redis using the REDIS_URL configuration variable:

...
c, err := redis.DialURL(os.Getenv("REDIS_URL"))
if err != nil {
    // Handle error
}
defer c.Close()
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment