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?
相关问题
- Getting Redis Master address from Sentinel C#
- Configuring Redis to play nice with AppHarbor
- MongoDB: groupby subdocument and count + add total
- Why do we need Redis for running CKAN?
- Problem in deserialize redis-cache to objects in S
Update redis 4.0
I just recently started reading about Redis, so I'm not positive. But, I did come across a few tidbits that may be useful.
Here's a snippet from http://antirez.com/post/redis-as-LRU-cache.html:
Also, Redis 2.0 has a VM mode where all keys must fit in memory, but the values for the rarely used keys can be on disk:
If you wonder what Redis (2.8) actually responds when it reaches the maximum defined by its configuration, it looks like this:
Redis is not a cache like memcached, by default (where the
maxmemory-policy
parameter is set tonoeviction
) all data you put into redis will not be removed, the only exception is in using EXPIRE.I recently experienced a no-free-memory situation and my application ground to a halt (writes not possible, reads were possible), running PHP scripts stopped dead in their tracks mid-way and had to be
kill -9
'd manually (even after memory was made available).I assumed data loss (or data inconsistency) had occurred so I did a
flushdb
and restored from backups. Lesson learned? Backups are your friend.If you have virtual memory functionality turned on (new in version 2.0 or 2.2, I think), then Redis starts to store the "not-so-frequently-used" data to disk when memory runs out.
If virtual memory in Redis is disabled, it appears as if the operating system's virtual memory starts to get used up (i.e. swap), and performance drops tremendously.
Now, you can also configure Redis with a maxmemory parameter, which prevents Redis from using any more memory (the default).
Newer versions of Redis have various policies when maxmemory is reached:
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 operation just fails miserably.
Some links for more info (since you shouldn't just take my word for it):