used_memory:由 Redis 分配器分配的内存总量,包含了redis进程内部的开销和数据占用的内存,以字节(byte)为单位redis
used_memory_rss:向操做系统申请的内存大小。与 top 、 ps等命令的输出一致。算法
used_memory_peak:redis的内存消耗峰值(以字节为单位)服务器
used_memory_peak_perc:使用内存达到峰值内存的百分比,即(used_memory/ used_memory_peak) *100%dom
used_memory_overhead:Redis为了维护数据集的内部机制所需的内存开销,包括全部客户端输出缓冲区、查询缓冲区、AOF重写缓冲区和主从复制的backlog。this
used_memory_startup:Redis服务器启动时消耗的内存lua
used_memory_dataset:数据占用的内存大小,即used_memory-sed_memory_overheadspa
used_memory_dataset_perc:数据占用的内存大小的百分比,100%*(used_memory_dataset/(used_memory-used_memory_startup))操作系统
total_system_memory:整个系统内存debug
used_memory_lua:Lua脚本存储占用的内存rest
maxmemory:Redis实例的最大内存配置
maxmemory_policy:当达到maxmemory时的淘汰策略
mem_fragmentation_ratio:碎片率,used_memory_rss/ used_memory
mem_allocator:内存分配器
active_defrag_running:表示没有活动的defrag任务正在运行,1表示有活动的defrag任务正在运行(defrag:表示内存碎片整理)
lazyfree_pending_objects:0表示不存在延迟释放的挂起对象
若是Redis的使用超过了设置的最大值会怎样?咱们来改一改上面的配置,故意把最大值设为1个byte试试。
# output buffers (but this is not needed if the policy is 'noeviction'). # # maxmemory <bytes> maxmemory 1
打开debug模式下的页面,提示错误:OOM command not allowed when used memory > ‘maxmemory’.
设置了maxmemory的选项,redis内存使用达到上限。能够经过设置LRU算法来删除部分key,释放空间。默认是按照过时时间的,若是set时候没有加上过时时间就会致使数据写满maxmemory。
若是不设置maxmemory或者设置为0,64位系统不限制内存,32位系统最多使用3GB内存。
LRU是Least Recently Used 近期最少使用算法。
若是设置了maxmemory,通常都要设置过时策略。打开Redis的配置文件有以下描述,Redis有六种过时策略:
# volatile-lru -> remove the key with an expire set using an LRU algorithm # allkeys-lru -> remove any key accordingly to the LRU algorithm # volatile-random -> remove a random key with an expire set # allkeys-random -> remove a random key, any key # volatile-ttl -> remove the key with the nearest expire time (minor TTL) # noeviction -> don't expire at all, just return an error on write operations
那么打开配置文件,添加以下一行,使用volatile-lru的过时策略:
maxmemory-policy volatile-lru
保存文件退出,重启redis服务。