Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
903 views
in Technique[技术] by (71.8m points)

nosql - What does Redis do when it runs out of memory?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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

  • 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.

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.

Some links for more info:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...