// Connect to local instance of Redis running on the default port. func ExampleDial(x int) { c, err := redis.Dial("tcp", ":6379") if err != nil { // handle error } defer c.Close() }
func redisConnection() redis.Conn { var connection redis.Conn var err error if len(os.Getenv("REDIS_URL")) > 0 { connection, err = redisurl.Connect() } else { connection, err = redis.Dial("tcp", ":6379") } check(err) return connection }
func ConnectToURL(s string) (c redis.Conn, err error) { redisURL, err := url.Parse(s) if err != nil { return } auth := "" if redisURL.User != nil { if password, ok := redisURL.User.Password(); ok { auth = password } } c, err = redis.Dial("tcp", redisURL.Host) if err != nil { fmt.Println(err) return } if len(auth) > 0 { _, err = c.Do("AUTH", auth) if err != nil { fmt.Println(err) return } } if len(redisURL.Path) > 1 { db := strings.TrimPrefix(redisURL.Path, "/") c.Do("SELECT", db) } return }