Redis: Check for connection on NewRDBWrapper()

This commit is contained in:
Noah Hilverling 2019-03-04 12:18:48 +01:00
parent cb018cea9d
commit dce9c0fa4f

View file

@ -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 {