我在使用codis连接到客户端时遇到问题

时间:2019-06-26 08:25:53

标签: java redis

使用codis群集,客户端连接池会出现以下错误:

2504429915944783937

我的代码:

redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
        at redis.clients.util.Pool.getResource(Pool.java:51)
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
        at io.codis.jodis.RoundRobinJedisPool.getResource(RoundRobinJedisPool.java:218)
        at com.br.hermes.center.service.impl.IndexServiceV3Impl.initLimitProductMap(IndexServiceV3Impl.java:2780)
        at com.br.hermes.center.quartz.SendMailQuartz.refreshFlowControllConfig(SendMailQuartz.java:608)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
        at java.util.concurrent.FutureTask.run(FutureTask.java)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.util.NoSuchElementException: Unable to validate object
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:506)
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
        at redis.clients.util.Pool.getResource(Pool.java:49)
        ... 19 more

配置:

@Configuration
public class CodisClientHA {

    private Logger logger = LogManager.getLogger(CodisClientHA.class);

    @Value("${codis.zkAddr}")
    private String zkAddr;

    @Value("${codis.zk.proxy.dir}")
    private String zkProxyDir;

    @Value("${codis.password}")
    private String password;

    @Value("${codis.timeout}")
    private int timeout;

    @Value("${codis.maxActive}")
    private int max_active;

    @Value("${codis.maxIdle}")
    private int max_idle;

    @Value("${codis.minIdle}")
    private int min_idle;

    @Value("${codis.maxWait}")
    private long max_wait;

    @Bean
    public JedisResourcePool getPool() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(max_idle);
        poolConfig.setMaxTotal(max_active);
        poolConfig.setTestOnBorrow(true);
        poolConfig.setTestOnReturn(true);
        poolConfig.setMaxWaitMillis(max_wait);
        poolConfig.setBlockWhenExhausted(false); 

        JedisResourcePool pool = RoundRobinJedisPool.create().poolConfig(poolConfig)
                .curatorClient(zkAddr, timeout).zkProxyDir(zkProxyDir).build();
        logger.info("------------------- Codis connection pool init succeed -------------------");
        return pool;
    }

使用jar:

codis.zkAddr=192.168.1.10:2181,192.168.1.11:2181,192.168.1.12:2181
codis.zk.proxy.dir=/jodis/codis
codis.timeout=30000
codis.password=
codis.maxIdle=100
codis.maxActive=1000
codis.maxWait=1000
codis.minIdle=50

我使用codis创建了一个新的spring boot项目,测试没有问题。将相同的代码放入实际的spring MVC项目中,并在启动时报告了错误,并且redis的连接池无法注入

帮助回答,非常感谢!

0 个答案:

没有答案