—————— Redis配置文件 redis.conf
如果不设置maxmemory或者设置为0,64位系统不限制内存,32位系统最多使用3GB内存。
# maxmemory <bytes>
maxmemory 268435456
如果设置了maxmemory,一般都要设置过期策略。打开Redis配置文件有如下描述,Redis有6种过期策略:
# 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 从已设置过期时间的数据集中挑选最近最少使用的数据淘汰
volatile-ttl 从已设置过期时间的数据集中挑选将要过期的数据淘汰
volatile-random 从已设置过期时间的数据集中任意选择数据淘汰
allkeys-lru 从所有数据集中挑选最近最少使用的数据淘汰;最常用的热点数据缓存策略
allkeys-random 从所有数据集中任意选择数据进行淘汰
no-envicition 禁止驱逐数据
添加如下一行,使用volatile-lru的过期策略:
maxmemory-policy allkeys-lru 存热点数据,启用 allkeys-lru 淘汰策略
重启redis服务
——————