Files
zeekay 5fa370e286 util/cache, util/webhook, util/helm: drop Argo wording from local identifiers
argoRedisHooks/NewArgoRedisHook, argoRepo/argoDB, argov1 and the
argoio/argoutils import aliases were the only things left saying Argo
in these packages; nothing here is matched by anything outside the
process. Also renames a leftover "staging-argocd-demo" branch name in
the webhook test fixtures.
2026-09-05 01:11:50 -07:00

42 lines
1006 B
Go

package cache
import (
"context"
"errors"
"net"
"github.com/hanzokv/go/v9"
log "github.com/sirupsen/logrus"
)
type redisReconnectHook struct {
reconnectCallback func()
}
func NewRedisReconnectHook(reconnectCallback func()) *redisReconnectHook {
return &redisReconnectHook{reconnectCallback: reconnectCallback}
}
func (hook *redisReconnectHook) DialHook(next kv.DialHook) kv.DialHook {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := next(ctx, network, addr)
return conn, err
}
}
func (hook *redisReconnectHook) ProcessHook(next kv.ProcessHook) kv.ProcessHook {
return func(ctx context.Context, cmd kv.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 *redisReconnectHook) ProcessPipelineHook(_ kv.ProcessPipelineHook) kv.ProcessPipelineHook {
return nil
}