func dialDb() (c redis.Conn, err error) { u, err := url.Parse(*redisServer) if err != nil { return nil, err } defer func() { if err != nil && c != nil { c.Close() } }() c, err = redis.Dial("tcp", u.Host) if err != nil { return } if *redisLog { l := log.New(os.Stderr, "", log.LstdFlags) c = redis.NewLoggingConn(c, l, "") } if u.User != nil { if pw, ok := u.User.Password(); ok { if _, err = c.Do("AUTH", pw); err != nil { return } } } return }
func (rs *RedisStore) conn() (conn redis.Conn, err error) { if rs.redis == nil { c, err2 := redis.Dial("tcp", rs.addr) if err2 != nil { return nil, err2 } if rs.logger != nil { c = redis.NewLoggingConn(c, rs.logger, rs.prefix) } if rs.password != "" { _, authErr := redis.String(c.Do("AUTH", rs.password)) if authErr != nil { err = authErr return } } if rs.db != "" { _, selDbErr := redis.String(c.Do("SELECT", rs.db)) if selDbErr != nil { err = selDbErr return } } rs.redis = c } return rs.redis, nil }
func dialDb() (redis.Conn, error) { redisUri, err := url.Parse(*redisServer) if err != nil { return nil, err } c, err := redis.Dial("tcp", redisUri.Host) if err != nil { return nil, err } if *redisLog { l := log.New(os.Stderr, "", log.LstdFlags) c = redis.NewLoggingConn(c, l, "") } if redisUri.User != nil { password, hasPassword := redisUri.User.Password() if hasPassword { _, err = redis.String(c.Do("AUTH", password)) if err != nil { return nil, err } } } return c, nil }
func (rs *RedisStore) conn() (c redis.Conn, err error) { pool, err := rs.GetPool(rs.addr, rs.password) if err != nil { return nil, err } c = pool.Get() if rs.logger != nil { c = redis.NewLoggingConn(c, rs.logger, rs.prefix) } return c, nil }