Search code examples
redisspring-data-redisredis-cluster

Redis eviction policy clarification


I'm new to Redis and could not find any information on that online so asking it here.
Suppose I have multiple database Redis cluster and I'm using LRU/LFU eviction policy.

I wonder if Redis eviction policy is database based? What I mean is, suppose I'm trying to insert a new item to DB 0 and I ran out of memory, will Redis evict items in DB 0 and complete the insertion? Or will it evict an item in any database based on the eviction policy?

I would expect that the eviction will be in the same virtual database.
In case the eviction policy is across different databases, what will happen if I reach the size limit of the database? Will it evict the keys inside that DB based on the eviction policy or the inserts will just fail?
Thanks.


Solution

  • I made a simple test to see it;

    127.0.0.1:6379> config get maxmemory
    1) "maxmemory"
    2) "0"
    127.0.0.1:6379> select 1
    OK
    127.0.0.1:6379[1]> config get maxmemory
    1) "maxmemory"
    2) "0"
    127.0.0.1:6379[1]> config set maxmemory 100mb
    OK
    127.0.0.1:6379[1]> config get maxmemory
    1) "maxmemory"
    2) "104857600"
    127.0.0.1:6379[1]> select 0
    OK
    127.0.0.1:6379> config get maxmemory
    1) "maxmemory"
    2) "104857600"
    127.0.0.1:6379> select 2
    OK
    127.0.0.1:6379[2]> config get maxmemory
    1) "maxmemory"
    2) "104857600"
    127.0.0.1:6379[2]>
    

    As you can see when you set maxmemory to the database 0, also other databases have the same maxmemory value. They all share the same resource(memory), when you run INFO MEMORY in any database they will print the same values (didn't share it -huge- but you can test).

    I think it is not database specific, they are just virtually separated. You don't run out of memory in only one database but all databases.