当前位置:网站首页>Use of jedispool

Use of jedispool

2022-06-22 05:16:00 a good idea

    @Bean
    public Jedis getJedis() {
        Jedis jedis = null;
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(50);
        jedisPoolConfig.setMaxIdle(10);
        // Set the maximum total number of instances
        jedisPoolConfig.setMaxTotal(150);
        // Control one pool How many states are there at most idle( Idle ) Of jedis example .
        jedisPoolConfig.setMaxIdle(30);
        jedisPoolConfig.setMinIdle(10);
        // Said when borrow( introduce ) One jedis When an instance , Maximum waiting time , If the wait time is exceeded , And just throw it out JedisConnectionException;
        jedisPoolConfig.setMaxWaitMillis(3 * 1000);
        // stay borrow One jedis When an instance , In advance or not alidate operation ; If true, Obtained jedis Instances are available ;
        jedisPoolConfig.setTestOnBorrow(true);
        // In the future pool when , In advance or not validate operation
        jedisPoolConfig.setTestOnReturn(true);
        jedisPoolConfig.setTestWhileIdle(true);
        jedisPoolConfig.setMinEvictableIdleTimeMillis(500);
        jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(1000);
        jedisPoolConfig.setTimeBetweenEvictionRunsMillis(1000);
        jedisPoolConfig.setNumTestsPerEvictionRun(100);
        // JedisPool jedisPool = new JedisPool(config, node, port);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, node, port, 5000, password);
        try {
            // From the connection pool jedis object
            jedis = jedisPool.getResource();
            return jedis;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }
        return jedis;
    }
 

原网站

版权声明
本文为[a good idea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220510552213.html