美文网首页
记一次线上redis事故排查。Could not get a r

记一次线上redis事故排查。Could not get a r

作者: 说再见谈何容易 | 来源:发表于2020-05-21 17:18 被阅读0次
图片.png

错误的伪代码

       Jedis client = getJedis();
        if (client == null) {
            return result;
        }
        try {
            result = client.setex(key,500,value);
        } catch (Exception e) {
            return null;
        } finally {
            if (null != client) {
                client.close();
            }
        }

当Jedis client = getJedis();抛异常时,导致其他业务的代码不执行。
修改后伪代码:

        Jedis client = null;
        try {
            client= getJedis();
            if (client == null) {
                return result;
            }
           client.setex(key,500,value);
        } catch (Exception e) {
            return null;
        } finally {
            if (null != client) {
                client.close();
            }
        }

造成Could not get a resource from the pool的原因在于maxTotal设置的过小,需根据系统的并发量,适当调整maxTotal大小

场景复现伪代码: maxTotal设置10


图片.png 图片.png

相关文章

网友评论

      本文标题:记一次线上redis事故排查。Could not get a r

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