Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Caching Server»How to Change Redis Max Memory

    How to Change Redis Max Memory

    By RahulDecember 21, 20222 Mins Read

    To configure the maximum amount of memory that Redis will use, you can use the `maxmemory` directive in the Redis configuration file (`redis.conf`). This directive takes an integer value, representing the maximum number of bytes that Redis will use to store data in memory.

    Advertisement

    For example, to set the maximum memory to `1GB`, (or 1024*1024*1024 bytes) you can use the following configuration:

    1
    maxmemory 1073741824

    You can also specify a policy for how Redis should handle the situation when the maximum memory limit is reached. This is done using the `maxmemory-policy` directive, which can take one of the following values:

    • noeviction: Redis will return an error when the maximum memory limit is reached and a new key needs to be added.
    • allkeys-lru: Redis will remove the least recently used keys in order to make space for new keys.
    • volatile-lru: Redis will remove the least recently used keys among keys with an expire set in order to make space for new keys.
    • allkeys-random: Redis will randomly select keys to remove in order to make space for new keys.
    • volatile-random: Redis will randomly select keys with an expire set to remove in order to make space for new keys.
    • volatile-ttl: Redis will remove keys with the shortest time to live in order to make space for new keys.

    For example, to set the `maxmemory-policy` to `allkeys-lru`, you can use the following configuration:

    1
    maxmemory-policy allkeys-lru

    Note that the maxmemory and maxmemory-policy directives must be set in the Redis configuration file (redis.conf) and cannot be set using the CONFIG SET command at runtime. You will need to restart Redis for the changes to take effect.

    It’s also worth noting that Redis will automatically try to free memory when it is running out of available memory, by releasing memory used by the least recently used keys. However, this process is limited by the maxmemory-samples directive, which determines the number of keys that Redis will sample in order to determine the keys to be removed. By default, this value is set to 3, so Redis will only sample 3 keys in order to determine the keys to be removed. You can adjust this value if needed by using the maxmemory-samples directive in the Redis configuration file.

    Memory Memory Limit redis
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Redis on Debian 11 Linux

    How to Install Redis on Debian 11 Linux

    How To Add Swap Space on Debian 11 (Bullseye)

    How To Add Swap Space on Debian 11

    How To Install Memcached on Ubuntu 20.04

    How To Install Memcached on Ubuntu 20.04

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.