public CustomLettucePool(String hostName, int port, String password, boolean ssl) {
this.redisHostName = hostName;
this.redisPort = port;
this.redisPassword = password;
this.redisUseSsl = ssl;
}
@Override
public RedisClient getClient() {
RedisURI.Builder redisUriBuilder = RedisURI.Builder.redis(redisHostName, redisPort);
if (redisUseSsl) {
redisUriBuilder.withSsl(redisUseSsl);
}
redisUriBuilder.withPassword(redisPassword);
RedisClient client = RedisClient.create(redisUriBuilder.build());
return client;
}
@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
CustomLettucePool lettucePool = new CustomLettucePool(redisHostName, redisPort, redisPassword, redisUseSsl);
lettucePool.setPoolConfig(poolConfig());
RedisClient client = lettucePool.getClient();
client.setOptions(clientOptions());
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(lettucePool);
connectionFactory.setValidateConnection(true);
connectionFactory.afterPropertiesSet();
return connectionFactory;
}