lchl0388 发表于 2016-12-18 11:40:11

redis-oom-command-not-allowed报错

  OOM command not allowed when used memory > 'maxmemory'.报错
作者:吴炳锡 来源:http://wubx.net/ 联系方式: wubingxi#163.com 转载请注明作/译者和出处,并且不能用于商业用途,违者必究.
OOM command not allowed when used memory > ‘maxmemory’ 报错排查
grep “OOM command not allowed when used memory > ‘maxmemory'” * -rsrc/redis.c: “-OOM command not allowed when used memory > ‘maxmemory’.\r\n”));
查看src/redis.c

 

 

shared.oomerr = createObject(REDIS_STRING,sdsnew(
"-OOM command not allowed when used memory > 'maxmemory'.\r\n"));
。。。
/* 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;
}
}
 



shared . oomerr = createObject ( REDIS_STRING , sdsnew (
"-OOM command not allowed when used memory > 'maxmemory'.\r\n" ) ) ;
。。。
/* 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 - & gt ; cmd - & gt ; flags & amp ; REDIS_CMD_DENYOOM ) & amp ; & amp ;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'.
 



#python t_redis.py
Traceback ( most recent call last ) :
File "t_redis.py" , line 21 , in & lt ; module & gt ;
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 , inexecute_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& gt ; 'maxmemory' .







结论:


[*]Redis运行中监控内存的使用情况.
[*]如果只做缓存使用,需要配置上lru策略,如 

 

 

maxmemory-policy allkeys-lru
maxmemory-samples 5
 



maxmemory - policy allkeys - lru
maxmemory - samples 5







如果做持久化存储说明,内存也不够用了。需要考虑增加内存。
[*]故障现场要看一下Redis的info输出,看看内存配是否达到了上限。
页: [1]
查看完整版本: redis-oom-command-not-allowed报错