内存使用统计
127.0.0.1:6379> info memory # Memory used_memory:674400 #Redis分配器分配的内存量,也就是实际存储数据的内存总量 used_memory_human:658.59K #以可读格式返回Redis使用的内存总量 used_memory_rss:3411968 #从操作系统的角度,Redis进程占用的总物理内存 used_memory_rss_human:3.25M used_memory_peak:675392 #内存分配器分配的最大内存,代表used_memory的历史峰值 used_memory_peak_human:659.56K used_memory_peak_perc:99.85% used_memory_overhead:662162 used_memory_startup:612424 used_memory_dataset:12238 used_memory_dataset_perc:19.75% allocator_allocated:1231000 allocator_active:1507328 allocator_resident:6131712 total_system_memory:1055457280 total_system_memory_human:1006.56M used_memory_lua:25600 #Lua引擎所消耗的内存 used_memory_lua_human:25.00K used_memory_scripts:0 used_memory_scripts_human:0B number_of_cached_scripts:0 maxmemory:3221225472 maxmemory_human:3.00G maxmemory_policy:noeviction allocator_frag_ratio:1.22 allocator_frag_bytes:276328 allocator_rss_ratio:4.07 allocator_rss_bytes:4624384 rss_overhead_ratio:0.56 rss_overhead_bytes:-2719744 mem_fragmentation_ratio:5.39 #used_memory_rss / used_memory比值,表示内存碎片率 mem_fragmentation_bytes:2778576 mem_not_counted_for_evict:0 mem_replication_backlog:0 mem_clients_slaves:0 mem_clients_normal:49550 mem_aof_buffer:0 mem_allocator:jemalloc-5.1.0 Redis所使用的内存分配器,默认是:jemalloc active_defrag_running:0 lazyfree_pending_objects:0
内存划分
缓存区
输入缓存区 : 最大1GB,超过后会被强制断开,不可动态设置。
输出缓存区 : 普通客户端 、slave客户端、pubsub客户端
内存设置上限
127.0.0.1:6379> config get maxmemory #指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区 1) "maxmemory" 2) "3221225472" 127.0.0.1:6379> config set maxmemory 2GB OK 127.0.0.1:6379> config rewrite OK
内存回收策略
删除过期键值 : 惰性删除、定时删除
内存溢出 : 超过maxmemory后触发策略,由maxmemory-policy控制