redis报错Could not get a resource from the pool 仅登录用户可见

时间:2023-02-10 12:08:59

解决同事线上生产环境报错需要解决,具体报错如下:

redis报错Could not get a resource from the pool 仅登录用户可见

查了查网上的资料,解决方案基本都是修改Redis的配置文件,将stop-writes-on-bgsave-error yes修改为 stop-writes-on-bgsave-error no;这是一个暂时性的解决方法。看了看*上的回答,最高赞回答是这样的,如下图:

redis报错Could not get a resource from the pool 仅登录用户可见

大概意思是:这是一个快速应急方法,如果你担心你的数据,那就首先检查下bgsave方法为什么会失败。bgsave方法是干什么的呢?咱来看下面这张图:

redis报错Could not get a resource from the pool 仅登录用户可见

bgsave方法为什么会失败呢?咱们看看大佬的回答:

redis报错Could not get a resource from the pool 仅登录用户可见

大概意思是(翻译不到位的地方,还请见谅,英文比较菜):在BGSAVE时,Redis会fork一个子进程,把数据保存到硬盘上。你可以通过查看日志来获取BGSAVE失败的原因(Linux系统里Redis日志文件通常是在/var/log/redis/redis-server.log),大多数时候BGSAVE失败的原因是fork进程分配不到内存。更多时候,fork进程分配不到内存是因为跟操作系统的优化相冲突,即使操作系统有足够的内存。(下面一大段就不翻译了,意思是可以Redis官网找到相应的解释,文末会把相关文章链接都缀上)。当然大神也给出了解决方案:

redis报错Could not get a resource from the pool 仅登录用户可见

参考链接:​https://*.com/questions/19581059/misconf-redis-is-configured-to-save-rdb-snapshots​http://redisdoc.com/persistence/bgsave.html#bgsave
https://redis.io/docs/getting-started/faq/