美文网首页 从0到1_后端开发
Redis获取连接池失败的原因剖析

Redis获取连接池失败的原因剖析

作者: ef43ffb32440 | 来源:发表于2017-12-22 14:35 被阅读360次

    今天打开网页提示服务器异常,查看服务器的log,发现了异常:

    Caused by: redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
        at redis.clients.util.Pool.getResource(Pool.java:51) ~[jedis-2.9.0.jar:?]
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.0.jar:?]
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16) ~[jedis-2.9.0.jar:?]
        at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194) ~[spring-data-redis-1.8.6.RELEASE.jar:?]
        ... 85 more
    Caused by: java.util.NoSuchElementException: Unable to validate object
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:506) ~[commons-pool2-2.4.2.jar:2.4.2]
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[commons-pool2-2.4.2.jar:2.4.2]
        at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.0.jar:?]
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.0.jar:?]
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16) ~[jedis-2.9.0.jar:?]
        at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194) ~[spring-data-redis-1.8.6.RELEASE.jar:?]
        ... 85 more
    
    

    大意就是获取连接池失败,在linux的terminal输入命令确保redis server开启:


    image.png

    输入命令redis-cli开启redis客户端,测试ping一下,发现错误;尝试插入一个值set test hello,一样的错误:

    image.png
    大意为:(错误)misconf redis被配置以保存数据库快照,但misconf redis目前不能在硬盘上持久化。用来修改数据集合的命令不能用,请使用日志的错误详细信息。

    这是由于强制停止redis快照,不能持久化引起的。

    运行info命令查看redis快照的状态,如下:


    image.png

    解决方案如下:

    运行config set stop-writes-on-bgsave-error no命令关闭配置项stop-writes-on-bgsave-error解决该问题。

    相关文章

      网友评论

        本文标题:Redis获取连接池失败的原因剖析

        本文链接:https://www.haomeiwen.com/subject/yuotgxtx.html