Question

I am quite new to redis and try to learn and explore the structure and architecture of redis.

Before version 2.4, there was Virtual Memory option available in redis by which one could swap the lesser used values to the disk, and from the disk whenever needed. Only hotspot data(frequently used) was kept in main memory.

But now as there is no option like Virtual Memory, how does redis deals with the scenario when the maximum space allocated to it gets filled up fully ?

How it removes data from the main memory, using which algorithm/process ? Can we write the data which is rarely used to disk without using Virtual Memory ?

Was it helpful?

Solution

Redis respects the maxmemory configuration directive. When set to 0 (the default), Redis will try to allocate as much memory as needed. Once it over does it, the OS will kill it.

Setting maxmemory to any positive value limits the amount of RAM that Redis will consume for data. When you reach the limit, Redis' behavior will depend on the maxmemory-policy configuration setting. The following is taken from the default redis.conf file and details the different evictions policies:

volatile-lru -> Evict using approximated LRU among the keys with an expire set.
allkeys-lru -> Evict any key using approximated LRU.
volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
allkeys-lfu -> Evict any key using approximated LFU.
volatile-random -> Remove a random key among the ones 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 evict anything, just return an error on write operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top