mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-30 09:30:00 -07:00
initial redis work, storage.Storage->storage.Conn,
among other new options in the config file for storage timeouts
This commit is contained in:
@@ -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{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user