Redis的LRU机制介绍
在Redis中,如果设置的maxmemory,那就要配置key的回收机制参数maxmemory-policy,默认volatile-lru,参阅Redis作者的原博客:antirez weblog >> Redis as an LRU cache
原文中写得很清楚:
复制代码 代码如下:
Another way to use Redis as a cache is the maxmemory directive, a feature that allows specifying a maximum amount of memory to use. When new data is added to the server, and the memory limit was already reached, the server will remove some old data deleting a volatile key, that is, a key with an EXPIRE (a timeout) set, even if the key is still far from expiring automatically.
在Redis服务器占用内存达到maxmemory的情况下,当再想增加内存占用时,会按maxmemory-policy机制将老的数据删除。这里简单说一下volatile-lru,Redis会按LRU算法删除设置了过期时间但还没有过期的key,而对于没有设置过期时间的key,Redis是永远保留的。当然,如果你不想删除没有过期的key,那可以使用noeviction机制
复制代码 代码如下:
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# 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
您可能感兴趣的文章
- 12-20使用DataGrip连接Hive的详细步骤
- 12-20debian10 mariadb安装过程详解
- 12-20MySQL索引失效的几种情况详析
- 12-20详解mysql持久化统计信息
- 12-20Robo可视化mongoDb实现操作解析
- 12-20MySQL 字段 LIKE 多个值
- 12-20Redis fork进程分配不到内存解决方案
- 12-20mysql插入前判断数据是否存在的操作
- 12-20基于navicat连接登录windows10本地wsl数据库
- 12-20Linux安装MariaDB数据库的实例详解


阅读排行
推荐教程
- 12-07mysql存储过程太慢怎么办
- 12-06redis通信协议(protocol)
- 12-05mysql的事务,隔离级别和锁用法实例分析
- 12-04MySQL一次性创建表格存储过程实战
- 12-03深入理解Redis内存淘汰策略
- 12-20PhpMyAdmin出现错误数据无法导出怎么办?
- 12-19Redis中实现查找某个值的范围
- 12-15浅析mysql迁移到clickhouse的5种方法
- 12-15CentOS7 64位下MySQL5.7安装与配置教程
- 12-14Mysql大型SQL文件快速恢复方案分享





