From 04da86d2cf0e0882c922048bd110e23932a68159 Mon Sep 17 00:00:00 2001 From: Manyanda Chitimbo Date: Fri, 14 Aug 2020 13:37:57 +0200 Subject: [PATCH] feat(redis): allow to configure redis connection pool Follows up https://github.com/quarkusio/quarkus/pull/9370#discussion_r443338006 and https://github.com/quarkusio/quarkus/issues/4453#issuecomment-674032630 --- .../client/runtime/RedisAPIProducer.java | 7 +++++ .../redis/client/runtime/RedisConfig.java | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java index 5db2ce94b2216d..3c3832b904fe7b 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java @@ -68,6 +68,13 @@ public RedisAPIProducer(RedisConfig config, Vertx vertx) { timeout = config.timeout.get().getSeconds(); } + options.setMaxPoolSize(config.maxPoolSize); + options.setMaxPoolWaiting(config.maxPoolWaiting); + options.setPoolRecycleTimeout(Math.toIntExact(config.poolRecycleTimeout.toMillis())); + if (config.poolCleanerInterval.isPresent()) { + options.setPoolCleanerInterval(Math.toIntExact(config.poolCleanerInterval.get().toMillis())); + } + vertxRedisClient = Redis.createClient(vertx, options); redisAPI = RedisAPI.api(vertxRedisClient); mutinyRedisClient = io.vertx.mutiny.redis.client.Redis.newInstance(vertxRedisClient); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisConfig.java index 321ff1a26e9c78..bba011bcd202bc 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisConfig.java @@ -48,4 +48,30 @@ public class RedisConfig { */ @ConfigItem(defaultValue = "standalone") public RedisClientType clientType; + + /** + * The maximum size of the connection pool. When working with cluster or sentinel. + *

+ * This value should be at least the total number of cluster member (or number of sentinels + 1) + */ + @ConfigItem(defaultValue = "6") + public int maxPoolSize; + + /** + * The maximum waiting requests for a connection from the pool. + */ + @ConfigItem(defaultValue = "24") + public int maxPoolWaiting; + + /** + * The duration indicating how often should the connection pool cleaner executes. + */ + @ConfigItem + public Optional poolCleanerInterval; + + /** + * The timeout for a connection recycling. + */ + @ConfigItem(defaultValue = "15") + public Duration poolRecycleTimeout; }