Esempio n. 1
0
// 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()
}
Esempio n. 2
0
File: util.go Progetto: the42/ogdat
// taken from https://github.com/soveran/redisurl/blob/master/redisurl.go
func GetRedisConnection(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 dbs := strings.Split(redisURL.Path, "/"); len(dbs) > 1 && dbs[1] != "" {
		c.Do("SELECT", dbs[1])
	}

	return
}