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

2020-05-21  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读