V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Aphsss
V2EX  ›  问与答

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

  •  
  •   Aphsss · 2018-08-29 22:42:54 +08:00 · 5724 次点击
    这是一个创建于 2079 天前的主题,其中的信息可能已经有所发展或是发生改变。

    程序是用的 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 这样

    感谢各位的解答

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5560 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:12 · PVG 15:12 · LAX 00:12 · JFK 03:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.