Redis only stores hot and high-frequency data 1. What is the memory setting of Redis on production (configured in the conf folder)
maxmemory determines the default configuration of redis (its unit is: byte type) The
default redis memory size: in There is no limit to the memory size under 64-bit operating systems. If it is a 32-bit operating system, the maximum memory is 3GB. The
production recommendation is three-quarters of the physical memory
. There are two ways to modify the memory settings:
1. conf file for configuration
2. redis Make changes dynamically
inside redis: operation commands
#设置最大内存 config set maxmemory 1024 #获取相关信息 config get maxmemory #查看redis的各种状态 info #查看redis内存状态 info maxmemory
2. Redis memory is full (redis memory exceeds the maximum limit) If you add data to redis, redis will have OOM exceptions. You can use redis's redis memory elimination strategy to solve this problem.
3. Redis's memory elimination mechanism
. Reasons why expired keys will not be deleted immediately:
Redis's three deletion strategies:
1. Timing deletion is
very unfriendly to the cpu, and the processor performance is traded in exchange for it. Storage space (change space by time)
2. Lazy deletion
Data will not be processed when it reaches the expiration time. When the data is accessed next time, it will be judged whether it has expired or not. If it is not expired, the data will be returned.
OK: not friendly to memory (in exchange for time)
3. Periodic deletion
adopts the strategy of regular random extraction.
Two methods of setting regular settings:
1. Modify the conf file: maxmemory-policy allkeys-lru
2. Enter the redis container, Use commands to modify
config set maxmemory-policy allkeys-lru