Skip to content

Commit

Permalink
Merge pull request #163 from SDCISA-13736-FixBadHabitsIn-DefaultRedis…
Browse files Browse the repository at this point in the history
…Provider
  • Loading branch information
hiddenalpha authored Jan 3, 2024
2 parents aca3d0d + d5b80d2 commit 1b13c2f
Showing 1 changed file with 15 additions and 6 deletions.
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

0 comments on commit 1b13c2f

Please sign in to comment.