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' .

结论:
  1. Redis运行中监控内存的使用情况.
  2. 如果只做缓存使用,需要配置上lru策略,如 
     

     

    maxmemory-policy allkeys-lru
     maxmemory-samples 5

     

    maxmemory - policy allkeys - lru

    maxmemory - samples 5

    如果做持久化存储说明,内存也不够用了。需要考虑增加内存。
  3. 故障现场要看一下Redis的info输出,看看内存配是否达到了上限。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值