MENU

Catalog

    redis报错OOM command not ***'maxmemory(二)

    December 10, 2018 • Read: 1705 • redis进阶阅读设置

    默认情况下,redis的最大内存是不限制的,如下:

    127.0.0.1:30003> CONFIG GET maxmemory
    1) "maxmemory"
    2) "0"
    

    我把它修改成了100M,然后向里面插数据:

    127.0.0.1:30003> CONFIG SET maxmemory 100
    OK
    127.0.0.1:30003> CONFIG GET maxmemory
    1) "maxmemory"
    2) "100"
    

    当内存达到接近100M的时候,出现以下错误:

    (error) OOM command not allowed when used memory > 'maxmemory'.
    

    这个时候可以理解。接下来我用FLUSHDB将数据库清空,用INFO查看:

    192.168.10.15:30005> FLUSHDB
    OK
    192.168.10.15:30005> INFO
    # Server
    redis_version:3.2.6
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:9aa069013865e216
    redis_mode:cluster
    os:Linux 4.4.0-51-generic x86_64
    arch_bits:64
    multiplexing_api:epoll
    gcc_version:4.8.4
    process_id:1439
    run_id:06be9bf801628e5c08f280067c6be609fb3ae8d5
    tcp_port:30005
    uptime_in_seconds:254023
    uptime_in_days:2
    hz:10
    lru_clock:14205482
    executable:/usr/local/redis-3.2.6/redis-server
    config_file:/usr/local/redis-3.2.6/cluster/30005/redis.conf
    
    # Clients
    connected_clients:9
    client_longest_output_list:0
    client_biggest_input_buf:0
    blocked_clients:0
    
    # Memory
    used_memory:2637448
    used_memory_human:2.52M
    used_memory_rss:110133248
    used_memory_rss_human:105.03M
    used_memory_peak:319544592
    used_memory_peak_human:304.74M
    total_system_memory:33655275520
    total_system_memory_human:31.34G
    used_memory_lua:37888
    used_memory_lua_human:37.00K
    maxmemory:100
    maxmemory_human:100B
    maxmemory_policy:noeviction
    mem_fragmentation_ratio:41.76
    mem_allocator:jemalloc-4.0.3
    
    # Persistence
    loading:0
    rdb_changes_since_last_save:1254332
    rdb_bgsave_in_progress:0
    rdb_last_save_time:1490353231
    rdb_last_bgsave_status:ok
    rdb_last_bgsave_time_sec:0
    rdb_current_bgsave_time_sec:-1
    aof_enabled:0
    aof_rewrite_in_progress:0
    aof_rewrite_scheduled:0
    aof_last_rewrite_time_sec:-1
    aof_current_rewrite_time_sec:-1
    aof_last_bgrewrite_status:ok
    aof_last_write_status:ok
    
    # Stats
    total_connections_received:137
    total_commands_processed:966215
    instantaneous_ops_per_sec:5
    total_net_input_bytes:210514819
    total_net_output_bytes:21337992636
    instantaneous_input_kbps:0.33
    instantaneous_output_kbps:5.29
    rejected_connections:0
    sync_full:1
    sync_partial_ok:0
    sync_partial_err:0
    expired_keys:0
    evicted_keys:0
    keyspace_hits:0
    keyspace_misses:0
    pubsub_channels:1
    pubsub_patterns:0
    latest_fork_usec:858
    migrate_cached_sockets:0
    
    # Replication
    role:master
    connected_slaves:1
    slave0:ip=192.168.10.14,port=30004,state=online,offset=195758203,lag=1
    master_repl_offset:195758203
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:194709628
    repl_backlog_histlen:1048576
    
    # CPU
    used_cpu_sys:243.60
    used_cpu_user:162.66
    used_cpu_sys_children:0.00
    used_cpu_user_children:0.00
    
    # Cluster
    cluster_enabled:1
    
    # Keyspace
    

    可以看到,redis使用的内存几乎清空,这个时候我再插数据:

    192.168.10.15:30005> set a 1
    (error) OOM command not allowed when used memory > 'maxmemory'.
    

    仍然出现了这个错误。

    后来才发现,是单位的原因,我以为CONFIG SET maxmemory 100的单位是M,实际上不是:

    maxmemory:100
    maxmemory_human:100B
    

    单位其实是Byte,怪不得出现这个错误了,将大小设置成100000000之后,就没出现错误了。

    maxmemory:100000000
    maxmemory_human:95.37M
    

    作者:茶褪色
    来源:存在的记忆
    原文:https://looaon.com/index.php/redis/817.html
    版权声明:本文为博主原创文章,转载请附上博文链接!

    兼总条贯 知至知终

    最后编辑于: January 15, 2019