mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
* chore: enable unused-parameter from revive Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * apply recommandations Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
42 lines
1002 B
Go
42 lines
1002 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type argoRedisHooks struct {
|
|
reconnectCallback func()
|
|
}
|
|
|
|
func NewArgoRedisHook(reconnectCallback func()) *argoRedisHooks {
|
|
return &argoRedisHooks{reconnectCallback: reconnectCallback}
|
|
}
|
|
|
|
func (hook *argoRedisHooks) DialHook(next redis.DialHook) redis.DialHook {
|
|
return func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
conn, err := next(ctx, network, addr)
|
|
return conn, err
|
|
}
|
|
}
|
|
|
|
func (hook *argoRedisHooks) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
|
return func(ctx context.Context, cmd redis.Cmder) error {
|
|
var dnsError *net.DNSError
|
|
err := next(ctx, cmd)
|
|
if err != nil && errors.As(err, &dnsError) {
|
|
log.Warnf("Reconnect to redis because error: \"%v\"", err)
|
|
hook.reconnectCallback()
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
func (hook *argoRedisHooks) ProcessPipelineHook(_ redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
|
return nil
|
|
}
|