The maxmemory setting limits how much memory Redis can use. This helps keep your server stable and prevents Redis from using too much memory.
Maxmemory setting in Redis
maxmemory <bytes>
maxmemory is set in bytes, but you can use suffixes like k, mb, gb for kilobytes, megabytes, and gigabytes.
You set this in the Redis configuration file (redis.conf) or at runtime with the CONFIG SET command.
maxmemory 100mbCONFIG SET maxmemory 536870912This example sets the maxmemory to 100 megabytes (100 * 1024 * 1024 = 104857600 bytes) and then retrieves the current maxmemory setting.
CONFIG SET maxmemory 104857600
CONFIG GET maxmemoryIf maxmemory is not set, Redis can use all available memory on the server.
Setting maxmemory alone does not control what Redis does when memory is full. You also need to set maxmemory-policy to decide how Redis evicts data.
maxmemory limits Redis memory use to keep your server stable.
You can set it in bytes or with size suffixes like mb or gb.
Use CONFIG SET to change it while Redis is running.
Practice
maxmemory setting in Redis control?Solution
Step 1: Understand the purpose of maxmemory
Themaxmemorysetting limits how much memory Redis can use to avoid overloading the server.Step 2: Compare options with this purpose
Only the maximum amount of memory Redis can use matches this description, others relate to clients, keys, or commands, which are unrelated.Final Answer:
The maximum amount of memory Redis can use -> Option AQuick Check:
maxmemory limits Redis memory use [OK]
- Confusing maxmemory with client limits
- Thinking maxmemory limits key size
- Assuming maxmemory limits command rate
CONFIG SET in Redis?Solution
Step 1: Recall Redis size suffix format
Redis accepts size suffixes like KB, MB, GB in uppercase for memory settings.Step 2: Check each option's suffix
CONFIG SET maxmemory 512MB uses 'MB' uppercase which is correct; CONFIG SET maxmemory 512mb uses lowercase 'mb' which is invalid; CONFIG SET maxmemory 512m uses 'm' which is not recognized; CONFIG SET maxmemory 512 has no suffix, so it's bytes, not megabytes.Final Answer:
CONFIG SET maxmemory 512MB -> Option BQuick Check:
Use uppercase suffixes like MB for megabytes [OK]
- Using lowercase suffixes like mb
- Using incomplete suffix like m
- Omitting suffix and expecting megabytes
CONFIG SET maxmemory 1GB executed on a Redis server, what will be the effect?Solution
Step 1: Interpret the command meaning
The command sets maxmemory to 1GB, meaning Redis should limit memory use to 1 gigabyte.Step 2: Validate the command syntax and effect
The syntax is correct and Redis supports 'GB' suffix, so it will enforce the memory limit.Final Answer:
Redis will limit its memory usage to 1 gigabyte -> Option AQuick Check:
CONFIG SET maxmemory 1GB limits memory to 1GB [OK]
- Thinking it sets unlimited memory
- Confusing bytes with gigabytes
- Expecting syntax error from correct command
CONFIG SET maxmemory 100mb on Redis but it returns an error. What is the likely cause?Solution
Step 1: Check Redis suffix case sensitivity
Redis requires uppercase suffixes like MB, GB for memory sizes.Step 2: Analyze the error cause
Using lowercase 'mb' causes syntax error; changing to 'MB' fixes it.Final Answer:
The suffix 'mb' is lowercase and invalid -> Option DQuick Check:
Use uppercase suffixes for memory sizes [OK]
- Assuming maxmemory can't be changed at runtime
- Using lowercase suffix causing errors
- Thinking maxmemory only accepts bytes
Solution
Step 1: Set maxmemory to 2 gigabytes correctly
UseCONFIG SET maxmemory 2GBwith uppercase suffix for 2 gigabytes.Step 2: Choose eviction policy that evicts keys automatically
allkeys-lruevicts least recently used keys from all keys, enabling automatic eviction.Step 3: Verify other options
Lowercase '2gb' with allkeys-random uses invalid suffix and random eviction; 2GB with noeviction disables eviction; 2048 (bytes, not GB) with volatile-lru limits to tiny memory and only evicts expiring keys.Final Answer:
CONFIG SET maxmemory 2GB and CONFIG SET maxmemory-policy allkeys-lru -> Option CQuick Check:
Set maxmemory + allkeys-lru for eviction [OK]
- Using lowercase suffix like '2gb'
- Choosing noeviction policy
- Setting maxmemory without suffix
- Using volatile-lru when all keys need eviction
Ready to prove it?
Pass the test and this pattern moves unknown
