Redis 内存不足时会做什么? [英] What does Redis do when it runs out of memory?

查看:43
本文介绍了Redis 内存不足时会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的问题,但我很难找到答案.Redis 2.0 如何处理最大分配内存不足的问题?它如何决定删除哪些数据或将哪些数据保留在内存中?

This might be easy question but I am having a hard time finding the answer. How does Redis 2.0 handle running out of maximum allocated memory? How does it decide which data to remove or which data to keep in memory?

推荐答案

如果你开启了虚拟内存功能( now deprecated),那么 Redis 开始存储not-so"- 经常使用"内存耗尽时将数据写入磁盘.

If you have virtual memory functionality turned on ( now deprecated), then Redis starts to store the "not-so-frequently-used" data to disk when memory runs out.

如果 Redis 中的虚拟内存被禁用(默认)并且设置了 maxmemory 参数(默认),Redis 将不会使用超过 maxmemory 允许的内存.如果关闭 maxmemory,Redis 将开始使用虚拟内存(即交换),性能将大幅下降.

If virtual memory in Redis is disabled (the default) and the maxmemory parameter is set (the default), Redis will not use any more memory than maxmemory allows. If you turn maxmemory off, Redis will start using virtual memory (i.e. swap), and performance will drop tremendously.

当达到 maxmemory 时,较新版本的 Redis 有各种策略:

Newer versions of Redis have various policies when maxmemory is reached:

  • volatile-lru - 删除其中的一个键那些有过期设置的,试图删除最近未使用的密钥.
  • volatile-ttl - 删除其中的一个键那些有过期设置的,试图删除剩余时间短的密钥生活.
  • volatile-random - 移除一个随机密钥过期设置.
  • allkeys-lru - 喜欢volatile-lru,但会删除每个一种钥匙,普通钥匙或钥匙设置了过期时间.
  • allkeys-random -像 volatile-random,但会移除各种键,都是普通键以及设置了过期时间的密钥.
  • volatile-lru - remove a key among the ones with an expire set, trying to remove keys not recently used.
  • volatile-ttl - remove a key among the ones with an expire set, trying to remove keys with short remaining time to live.
  • volatile-random - remove a random key among the ones with an expire set.
  • allkeys-lru - like volatile-lru, but will remove every kind of key, both normal keys or keys with an expire set.
  • allkeys-random - like volatile-random, but will remove every kind of keys, both normal keys and keys with an expire set.

如果你选择一个只删除带有 EXPIRE 集的键的策略,那么当 Redis 内存不足时,看起来程序只是中止了 malloc() 操作.也就是说,如果您尝试存储更多数据,写入操作就会失败.

If you pick a policy that only removes keys with an EXPIRE set, then when Redis runs out of memory, it looks like the program just aborts the malloc() operation. That is, if you try to store more data, the write operation simply fails.

更多信息的链接:

这篇关于Redis 内存不足时会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆