Skip to content

Commit

Permalink
Added support for Redis authentication, updated redigo to latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbarch committed Feb 24, 2016
1 parent 2cacfab commit 93d8247
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 148 deletions.
4 changes: 2 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backends/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func New(config Config) (StoreClient, error) {
case "rancher":
return rancher.NewRancherClient(backendNodes)
case "redis":
return redis.NewRedisClient(backendNodes)
return redis.NewRedisClient(backendNodes, config.ClientKey)
case "env":
return env.NewEnvClient()
case "vault":
Expand Down
24 changes: 18 additions & 6 deletions backends/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Client struct {
// Iterate through `machines`, trying to connect to each in turn.
// Returns the first successful connection or the last error encountered.
// Assumes that `machines` is non-empty.
func tryConnect(machines []string) (redis.Conn, error) {
func tryConnect(machines []string, options ...string) (redis.Conn, error) {
var err error
for _, address := range machines {
var conn redis.Conn
Expand All @@ -27,7 +27,19 @@ func tryConnect(machines []string) (redis.Conn, error) {
network = "unix"
}
log.Debug(fmt.Sprintf("Trying to connect to redis node %s", address))
conn, err = redis.DialTimeout(network, address, time.Second, time.Second, time.Second)

dialops := []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialReadTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
}

if len(options) > 0 {
dialops = append(dialops, redis.DialPassword(options[0]))
}

conn, err = redis.Dial(network, address, dialops...)

if err != nil {
continue
}
Expand All @@ -54,7 +66,7 @@ func (c *Client) connectedClient() (redis.Conn, error) {
// Existing client could have been deleted by previous block
if c.client == nil {
var err error
c.client, err = tryConnect(c.machines)
c.client, err = tryConnect(c.machines, c.options)
if err != nil {
return nil, err
}
Expand All @@ -65,10 +77,10 @@ func (c *Client) connectedClient() (redis.Conn, error) {

// NewRedisClient returns an *redis.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewRedisClient(machines []string) (*Client, error) {
func NewRedisClient(machines []string, options ...string) (*Client, error) {
var err error
clientWrapper := &Client{ machines : machines, client: nil }
clientWrapper.client, err = tryConnect(machines)
clientWrapper := &Client{ machines : machines, options : options, client: nil }
clientWrapper.client, err = tryConnect(machines, options)
return clientWrapper, err
}

Expand Down
175 changes: 175 additions & 0 deletions vendor/github.com/garyburd/redigo/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/garyburd/redigo/internal/commandinfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 0 additions & 65 deletions vendor/github.com/garyburd/redigo/internal/redistest/testdb.go

This file was deleted.

Loading

0 comments on commit 93d8247

Please sign in to comment.