diff --git a/redis.go b/redis.go index e6dd48cf..816456b6 100644 --- a/redis.go +++ b/redis.go @@ -82,10 +82,15 @@ func (rdbw *RDBWrapper) CompareAndSetConnected(connected bool) (swapped bool) { } } -func NewRDBWrapper(rdb *redis.Client) *RDBWrapper { +func NewRDBWrapper(rdb *redis.Client) (*RDBWrapper, error) { rdbw := RDBWrapper{Rdb: rdb, ConnectedAtomic: new(uint32)} rdbw.ConnectionUpCondition = sync.NewCond(&sync.Mutex{}) + res := rdbw.Rdb.Ping() + if res.Err() != nil { + return nil, res.Err() + } + go func() { for { rdbw.CheckConnection(true) @@ -93,7 +98,7 @@ func NewRDBWrapper(rdb *redis.Client) *RDBWrapper { } }() - return &rdbw + return &rdbw, nil } func (rdbw *RDBWrapper) getConnectionCheckInterval() time.Duration {