forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Redis should reconnect on connectivity issue (argoproj#7207)
fix: Redis should reconnect on connectivity issue (argoproj#7207) Signed-off-by: pashavictorovich <[email protected]>
- Loading branch information
1 parent
9cf71be
commit 6f794d0
Showing
3 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/go-redis/redis/v8" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const NoSuchHostErr = "no such host" | ||
|
||
type argoRedisHooks struct { | ||
reconnectCallback func() | ||
} | ||
|
||
func NewArgoRedisHook(reconnectCallback func()) *argoRedisHooks { | ||
return &argoRedisHooks{reconnectCallback: reconnectCallback} | ||
} | ||
|
||
func (hook *argoRedisHooks) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) { | ||
return ctx, nil | ||
} | ||
|
||
func (hook *argoRedisHooks) AfterProcess(ctx context.Context, cmd redis.Cmder) error { | ||
if cmd.Err() != nil && strings.Contains(cmd.Err().Error(), NoSuchHostErr) { | ||
log.Warnf("Reconnect to redis because error: \"%v\"", cmd.Err()) | ||
hook.reconnectCallback() | ||
} | ||
return nil | ||
} | ||
|
||
func (hook *argoRedisHooks) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) { | ||
return ctx, nil | ||
} | ||
|
||
func (hook *argoRedisHooks) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters