OOM command not allowed when used memory > ‘maxmemory’ 报错排查
grep “OOM command not allowed when used memory > ‘maxmemory’” * -r
src/redis.c: “-OOM command not allowed when used memory > ‘maxmemory’.rn”));
查看src/redis.c
shared.oomerr = createObject(REDIS_STRING,sdsnew( "-OOM command not allowed when used memory > 'maxmemory'.rn")); 。。。 /* Handle the maxmemory directive. * * First we try to free some memory if possible (if there are volatile * keys in the dataset). If there are not the only thing we can do * is returning an error. */ if (server.maxmemory) { int retval = freeMemoryIfNeeded(); if ((c->cmd->flags & REDIS_CMD_DENYOOM) && retval == REDIS_ERR) { flagTransaction(c); addReply(c, shared.oomerr); return REDIS_OK; } }
从代码确认报这个错,大概是内存达到最大限时不能释放出来内存报的错。
做一个简单的验证:
配置一个10M大小的Redis,利用一个python程序往里面写数据,很快得到报错:
#python t_redis.py Traceback (most recent call last): File "t_redis.py", line 21, in <module> start() File "t_redis.py", line 15, in start s = r.set(key, v1) File "/usr/lib/python2.6/site-packages/redis/client.py", line 647, in set return self.execute_command('SET', name, value) File "/usr/lib/python2.6/site-packages/redis/client.py", line 330, in execute_command **options File "/usr/lib/python2.6/site-packages/redis/client.py", line 312, in _execute_command return self.parse_response(command_name, **options) File "/usr/lib/python2.6/site-packages/redis/client.py", line 390, in parse_response response = self._parse_response(command_name, catch_errors) File "/usr/lib/python2.6/site-packages/redis/client.py", line 349, in _parse_response raise ResponseError(response) redis.exceptions.ResponseError: OOM command not allowed when used memory > 'maxmemory'.
结论:
- Redis运行中监控内存的使用情况.
- 如果只做缓存使用,需要配置上lru策略,如
maxmemory-policy allkeys-lru maxmemory-samples 5
如果做持久化存储说明,内存也不够用了。需要考虑增加内存。
- 故障现场要看一下Redis的info输出,看看内存配是否达到了上限。
转载请注明:爱开源 » redis-oom-command-not-allowed报错