initial redis work, storage.Storage->storage.Conn,

among other new options in the config file for storage timeouts
This commit is contained in:
Jimmy Zelinskie
2013-06-24 14:18:32 -04:00
parent 79a6c79067
commit 56132e3d64
5 changed files with 60 additions and 10 deletions

View File

@@ -5,5 +5,46 @@
package redis
import (
"github.com/garyburd/redigo/redis"
"github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/storage"
)
type driver struct{}
func (d *driver) New(conf *config.Storage) (storage.Conn, error) {
var (
conn redis.Conn
err error
)
if conf.ConnectTimeout != nil &&
conf.ReadTimeout != nil &&
conf.WriteTimeout != nil {
conn, err = redis.DialTimeout(
conf.Network,
conf.Addr,
conf.ConnectTimeout.Duration,
conf.ReadTimeout.Duration,
conf.WriteTimeout.Duration,
)
} else {
conn, err = redis.Dial(conf.Network, conf.Addr)
}
if err != nil {
return nil, err
}
return &Conn{
conn,
}, nil
}
type Conn struct {
conn redis.Conn
}
func init() {
storage.Register("redis", &driver{})
}