小编Par*_*een的帖子

连接池如何使用 Spring Boot 应用程序与 RedisTemplate 配合使用

我有以下用于获取 RedisTemplate 的代码片段。

@Bean
public JedisConnectionFactory getJedisConnectionFactory() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(host);
    if (!StringUtils.isEmpty(password)) {
        redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
    }
    redisStandaloneConfiguration.setPort(port);
    return new JedisConnectionFactory(redisStandaloneConfiguration, getJedisClientConfiguration());
}

@Bean
public RedisTemplate redisTemplate() {
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
    redisTemplate.setConnectionFactory(getJedisConnectionFactory());
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    return redisTemplate;
Run Code Online (Sandbox Code Playgroud)

}

我的问题是 sprint-boot 如何理解连接池,因为我没有在工厂中提供有关连接池的任何信息。我的应用程序属性文件具有以下属性。

redis.host=<redis-host>
redis.port=<port>
redis.password=<password>
redi.jedis.pool.max.total=16
redi.jedis.pool.max.idle=8
redi.jedis.pool.min.idle=4
Run Code Online (Sandbox Code Playgroud)

java spring spring-data-redis spring-boot

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-data-redis ×1