Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDCISA-13736] Fix bad habits in DefaultRedisProvider. #163

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/main/java/org/swisspush/reststorage/DefaultRedisProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ private Future<RedisAPI> connectToRedis() {
createConnectStrings().forEach(redisOptions::addConnectionString);
redis = Redis.createClient(vertx, redisOptions);

redis.connect().onSuccess(conn -> {
redis.connect().onComplete( ev -> {
if( ev.failed() ) {
promise.fail(new Exception("redis.connect()", ev.cause()));
connecting.set(false);
return;
}
var conn = ev.result();
log.info("Successfully connected to redis");
client = conn;

Expand All @@ -114,23 +120,26 @@ private Future<RedisAPI> connectToRedis() {
// eg, the underlying TCP connection is closed but the client side doesn't know it yet
// the client tries to use the staled connection to talk to server. An exceptions will be raised
if (reconnectEnabled()) {
conn.exceptionHandler(e -> attemptReconnect(0));
conn.exceptionHandler(ex -> {
log.warn("redis connection reports problem", ex);
attemptReconnect(0);
});
}

// make sure the client is reconnected on connection close
// eg, the underlying TCP connection is closed with normal 4-Way-Handshake
// this handler will be notified instantly
if (reconnectEnabled()) {
conn.endHandler(placeHolder -> attemptReconnect(0));
conn.endHandler(nothing -> {
log.warn("redis connection got closed");
attemptReconnect(0);
});
}

// allow further processing
redisAPI = RedisAPI.api(conn);
promise.complete(redisAPI);
connecting.set(false);
}).onFailure(t -> {
promise.fail(t);
connecting.set(false);
});
} else {
promise.complete(redisAPI);
Expand Down