Nodejs Redis客户端报错Error: OOM command not allowed when used memory > ‘maxmemory‘

标题中的错误是由Redis服务端返回给客户端的,属于服务端错误。原因是Redis服务的内存占用已经达到maxmemory所设的限定,并且Eviction policies(由maxmemory-policy参数设置)没有删除掉足够多的key来释放空间。

由上述错误可能会进而引发Redis客户端报如下错误:

Error: TypeError: Cannot read property 'length' of undefined
    at Command.callback (/usr/local/project/node_modules/fun_redis/node_modules/redis/index.js:1090:36)

火线修复:

在线配置redis,增大maxmemory,示例如下设置成8GB

config set maxmemory 8589934592


 

不仅仅是noeviction策略会导致这个错误,volatile-*策略也有可能报这个错,如果找不到足够多带有过期时间的key的话。

Eviction policies

  • noeviction: return errors when the memory limit was reached and the client is trying to execute commands that could result in more memory to be used (most write commands, but DEL and a few more exceptions).
  • allkeys-lru: evict keys by trying to remove the less recently used (LRU) keys first, in order to make space for the new data added.
  • volatile-lru: evict keys by trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added.
  • allkeys-random: evict keys randomly in order to make space for the new data added.
  • volatile-random: evict keys randomly in order to make space for the new data added, but only evict keys with an expire set.
  • volatile-ttl: evict keys with an expire set, and try to evict keys with a shorter time to live (TTL) first, in order to make space for the new data added.

2021.02.07 Update:

之前忘了把对应的slave实例的maxmemory调高,结果发现slave实例的keys数比master实例少很多,一直保持在一个数量而不再增长,更主要的是并没有直接的错误报出来,所以不易发现。因此,对于主从节点的keys数量差异有必要增加监控报警脚本。

猜你喜欢

转载自blog.csdn.net/pengpengzhou/article/details/112307659