Skip to content

Commit

Permalink
feat(redis): allow to configure redis connection pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 4e49e05 commit 98d53d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

import io.quarkus.redis.client.RedisClient;
import io.quarkus.redis.client.reactive.ReactiveRedisClient;
Expand All @@ -16,6 +17,7 @@
import io.vertx.redis.client.RedisClientType;
import io.vertx.redis.client.RedisOptions;

@ApplicationScoped
class RedisAPIProducer {
private static final char AT = '@';
private static final char COLON = ':';
Expand All @@ -27,29 +29,17 @@ class RedisAPIProducer {

private final RedisConfig config;

@Produces
@ApplicationScoped
private final Redis vertxRedisClient;

@Produces
@ApplicationScoped
private final RedisAPI redisAPI;

@Produces
@ApplicationScoped
private final RedisClient redisClient;

@Produces
@ApplicationScoped
private final ReactiveRedisClient reactiveClient;

@Produces
@ApplicationScoped
private final MutinyRedisClient mutinyRedisClient;
private final io.vertx.mutiny.redis.client.Redis mutinyRedisClient;

@Produces
@ApplicationScoped
private final MutinyRedisClientAPI mutinyRedisClientAPI;
private final io.vertx.mutiny.redis.client.RedisAPI mutinyRedisAPI;

public RedisAPIProducer(RedisConfig config, Vertx vertx) {
this.config = config;
Expand Down Expand Up @@ -87,15 +77,51 @@ public RedisAPIProducer(RedisConfig config, Vertx vertx) {

vertxRedisClient = Redis.createClient(vertx, options);
redisAPI = RedisAPI.api(vertxRedisClient);
mutinyRedisClient = new MutinyRedisClient(vertxRedisClient);
mutinyRedisClientAPI = new MutinyRedisClientAPI(redisAPI);
redisClient = new RedisClientImpl(mutinyRedisClientAPI, timeout);
reactiveClient = new ReactiveRedisClientImpl(mutinyRedisClientAPI);
mutinyRedisClient = io.vertx.mutiny.redis.client.Redis.newInstance(vertxRedisClient);
mutinyRedisAPI = io.vertx.mutiny.redis.client.RedisAPI.api(mutinyRedisClient);
redisClient = new RedisClientImpl(mutinyRedisAPI, timeout);
reactiveClient = new ReactiveRedisClientImpl(mutinyRedisAPI);
}

@Produces
@Singleton
Redis redis() {
return vertxRedisClient;
}

@Produces
@Singleton
RedisAPI redisAPI() {
return redisAPI;
}

@Produces
@Singleton
RedisClient redisClient() {
return redisClient;
}

@Produces
@Singleton
ReactiveRedisClient reactiveRedisClient() {
return reactiveClient;
}

@Produces
@Singleton
io.vertx.mutiny.redis.client.Redis mutinyRedisClient() {
return mutinyRedisClient;
}

@Produces
@Singleton
io.vertx.mutiny.redis.client.RedisAPI mutinyRedisAPI() {
return mutinyRedisAPI;
}

@PreDestroy
public void close() {
this.redisAPI.close();
this.redis().close();
}

private String buildConnectionString(InetSocketAddress address) {
Expand All @@ -114,24 +140,4 @@ private String buildConnectionString(InetSocketAddress address) {

return builder.toString();
}

static class MutinyRedisClient extends io.vertx.mutiny.redis.client.Redis {
MutinyRedisClient(Redis delegate) {
super(delegate);
}

MutinyRedisClient() {
super(null);
}
}

static class MutinyRedisClientAPI extends io.vertx.mutiny.redis.client.RedisAPI {
MutinyRedisClientAPI(RedisAPI delegate) {
super(delegate);
}

MutinyRedisClientAPI() {
super(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,4 @@ public class RedisConfig {
*/
@ConfigItem(defaultValue = "15")
public Duration poolRecycleTimeout;

/**
* Sets how much handlers is the client willing to queue.
* <p>
* The client will always work on pipeline mode, this means that messages can start queueing.
* Using this configuration option, you can control how much backlog you're willing to accept.
*/
@ConfigItem(defaultValue = "2048")
public int maxWaitingHandlers;

/**
* Tune how much nested arrays are allowed on a redis response. This affects the parser performance.
*/
@ConfigItem(defaultValue = "32")
public int maxNestedArrays;
}

0 comments on commit 98d53d1

Please sign in to comment.