springboot 到底怎么配置 Redis 的连接池啊

2018 年 8 月 29 日
 Aphsss

程序是用的 Idea 创建的 2.1.0.M1 版本的 spring-boot-starter-parent, 用的 spring-boot-starter-data-redis2.6.0版本的 commons-pool2 依赖

application.properties 的配置是

spring.redis.host= 127.0.0.1
spring.redis.port= 6379
spring.redis.lettuce.pool.max-active= 8
spring.redis.lettuce.pool.max-idle= 4
spring.redis.lettuce.pool.min-idle= 4
spring.redis.lettuce.pool.max-wait= -1ms

代码块 1:

@Configuration
public class RedisConfigure {

  @Autowired
  RedisConnectionFactory redisConnectionFactory;

  @Bean("conn")
  RedisConnection getConn() {
    return redisConnectionFactory.getConnection();
  }

  @Bean
  RedisTemplate<String, UserEntity> userEntityRedisTemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<String, UserEntity> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    return template;
  }
}

代码块 2:

  @Autowired
  RedisTemplate<String, UserEntity> userEntityRedisTemplate;

  public Long saveToRedisMessageQueue() {
    return userEntityRedisTemplate.opsForList().leftPush("message:q", new UserEntity("lisi","passwd"));
  }

此时 Redis 是零连接的,我在 redis-cli 里面执行info clientsconnected_clients:1

然后启动程序,现在程序是可以操作 Redis 的,但是我在 redis-cli 里面执行info clientsconnected_clients:2

啊啊啊啊啊。为什么不是 connected_clients:5 啊,怎么才能变成connected_clients:5 这样

感谢各位的解答

6057 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.xtra.eu.org/t/484397

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX