############################## MEMORY MANAGEMENT ################################# Set a memory usage limit to the specified amount of bytes.# When the memory limit is reached Redis will try to remove keys# according to the eviction policy selected (see maxmemory-policy).# 限制内存使用,如果使用内存达到了限制会按照eviction策略来移除对应的key## If Redis can't remove keys according to the policy, or if the policy is# set to 'noeviction', Redis will start to reply with errors to commands# that would use more memory, like SET, LPUSH, and so on, and will continue# to reply to read-only commands like GET.#如果不能移除key或者策略是noeviction,当操作set,lpush这样需要内存的命令时,redis会给命令返回错误提示需要更多的内存,#如果是get这样的只读命令则会继续响应## This option is usually useful when using Redis as an LRU or LFU cache, or to# set a hard memory limit for an instance (using the 'noeviction' policy).# 这个配置在降Redis当做LRU或者LFU缓存的时候非常有用,或者使用noeviction配置给redis限制一个硬性的内存限制## WARNING: If you have slaves attached to an instance with maxmemory on,# the size of the output buffers needed to feed the slaves are subtracted# from the used memory count, so that network problems / resyncs will# not trigger a loop where keys are evicted, and in turn the output# buffer of slaves is full with DELs of keys evicted triggering the deletion# of more keys, and so forth until the database is completely emptied.# 如果你开起了maxmemory并对实例设置了slave,那么为了满足slave而需要的output buffers会从使用内存中扣减,这样# 网络问题或者resyncs不会触发key的循环驱逐,反过来如果output buffers已满,删除键会触发删除更多的键,直到数据库清空### In short... if you have slaves attached it is suggested that you set a lower# limit for maxmemory so that there is some free RAM on the system for slave# output buffers (but this is not needed if the policy is 'noeviction').# 如果你对redis示例设置了slave,那么建议你设置一个小一点的maxmemory来保证系统有足够的RAM作为slave output buffers### maxmemory <bytes># MAXMEMORY POLICY: how Redis will select what to remove when maxmemory# is reached. You can select among five behaviors:# 内存策略,当maxmemory到达之后,如何选择key来删除,是依据此策略,下面是可选的策略### volatile-lru -> Evict using approximated LRU among the keys with an expire set.# 对过期的key使用最近最少使用的策略淘汰# allkeys-lru -> Evict any key using approximated LRU.# 对全部的key使用最近最少使用的策略淘汰# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.# 对过期的key使用最近最不常用的策略淘汰# allkeys-lfu -> Evict any key using approximated LFU.# 对全部的key使用最近最不常用的策略淘汰# volatile-random -> Remove a random key among the ones with an expire set.# 对过期的key使用随机策略淘汰# allkeys-random -> Remove a random key, any key.# 对全部的key使用随机策略淘汰# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)# 淘汰ttl最短的key# noeviction -> Don't evict anything, just return an error on write operations.# 不淘汰任何key。内存满时,可进行读操作(get等),写操作将返回错误。这是Redis的默认模式,该模式下内存达到最大的时候,Redis就只能读不能写了。# LRU means Least Recently Used# LFU means Least Frequently Used## LRU, LFU 和 volatile-ttl都是使用的近似算法# Both LRU, LFU and volatile-ttl are implemented using approximated randomized algorithms.## Note: with any of the above policies, Redis will return an error on write# operations, when there are no suitable keys for eviction.## At the date of writing these commands are: set setnx setex append# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby# getset mset msetnx exec sort## The default is:## maxmemory-policy noeviction# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated# algorithms (in order to save memory), so you can tune it for speed or# accuracy. For default Redis will check five keys and pick the one that was# used less recently, you can change the sample size using the following# configuration directive.# LRU, LFU 和 volatile-ttl都是使用的近似算法,不是精确算法(为了节约内存),你可以调整它的速度或准确性。默认Redis会选择5个key在其中选一个最近最少使用的,这个样本大小可以通过 maxmemory-samples设置,### The default of 5 produces good enough results. 10 Approximates very closely# true LRU but costs more CPU. 3 is faster but not very accurate.# 默认值为5会产生足够好的结果, 10非常接近真正的LRU但成本更高的CPU, 3更快但不是很准确。## maxmemory-samples 5