Set the maximum cache redis

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_35959554/article/details/98940136

        Setting the maximum cache (memory) has two advantages, first, to avoid resource exhaustion and collapse of the system, but too much will inevitably affect the efficiency of such data cache memory management. And set the maximum cache when you want to cache data is greater than the maximum cache, and does not cause OOM, Redis will be eliminated do not think he is hot data according to policy mode.

        Set the maximum cache into the first redis installation directory, run redis-cli.exe program , enter CONFIG GET *   command to get all the items that can be set to find " maxmemory " below to view the display is the number (0 means unlimited).

Use CONFIG SET maxmemory 3gb  command to set the maximum cache 3gb.

Memory Size Conversion:
    1K => 1000 bytes
    1KB => 1024 bytes
    1M => 1000000 bytes
    1MB => 1024 * 1024 bytes
    1g => 1000000000 bytes
    1GB => 1024 * 1024 * 1024 bytes

       After setting the maximum cache of course, you need to specify maxmemory-policy strategy mode (the default is noeviction), using the CONFIG the SET maxmemory-policy  AllKeys the LRU-  command to set the recovery key Least Recently Used (LRU) cache of reaching the maximum.

Strategy mode:
        volatile-the LRU -> Recycling least recently used (LRU) key, but only the recovery of overdue set of keys, to make room for new data;
        AllKeys-the LRU -> Recycling least recently used (LRU) keys to to make room for new data;
        volatile random--> recovered random key, but only the recovery of the key is provided expired, to make room for the new data;
        AllKeys-random -> recovered random key, to make room for the new data;
        volatile -ttl -> recycling has set an expiration of keys, try to recover from key TTL shortest time to make room for new data;
        noeviction -> ban out of the data and return an error when reaching the memory limit. When the client attempts to execute the command will lead to more memory footprint (most of the write command, and apart from some exceptions DEL).

Guess you like

Origin blog.csdn.net/weixin_35959554/article/details/98940136